Tuesday, December 19, 2017

LockerService


The LockerService architectural layer enhances security by isolating individual Lightning components in their own containers and enforcing coding best practices.
  • LockerService implicitly enables JavaScript ES5 strict mode.
  • A component can only traverse the DOM and access elements created by a component in the same namespace. You can’t use component.find("button1").getElement() to access the DOM element created by <lightning:button>.
  • LockerService applies restrictions to global references. LockerService provides secure versions of non-intrinsic objects, such as window. For example, the secure version of window is SecureWindow.
Salesforce have decoupled the Content Security Policy (CSP) from LockerService and have made it available as a critical security update.

References:
LockerService API Viewer app: http://documentation.auraframework.org/lockerApiTest/index.app?aura.mode=DEV
Share This:    Facebook Twitter

Sunday, December 3, 2017

Asynchronous Apex: Using future methods

You can call a future method
  • for executing long-running operations, such as callouts to external Web services or any operation you’d like to run in its own thread, on its own time.
  • to isolate DML operations on different sObject types to prevent the mixed DML error.
  • for taking advantage of higher governor limits

DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction. However, deleting a DML operation has no restrictions.

Methods with the future annotation must be static methods, and can only return a void type. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types.
global class FutureMethodRecordProcessing {
    @future
    public static void processRecords(List<ID> recordIds) {   
         List<Account> accts = [SELECT Name FROM Account WHERE Id IN :recordIds];
         // Process records
    }
}

Methods with the future annotation have the following limits:
  • No more than 50 method calls per Apex invocation
  • The maximum number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater.

How methods with future annotation can take sObjects or objects as arguments?
https://developer.salesforce.com/blogs/developer-relations/2013/06/passing-objects-to-future-annotated-methods.html

How to call a future method from a batch class?
https://salesforce.stackexchange.com/questions/24843/calling-future-method-from-batch

Share This:    Facebook Twitter

Apex: Get number of contacts for a list of accounts

Map<Id, Account> accountsById = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);
Set<Id> accountIds = accountsById.keySet();

Map<Id, Integer> numberOfContacts = new Map<Id, Integer>();
for (Account acc : [SELECT Id, Name, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds]) {
    numberOfContacts.put(acc.Id, acc.Contacts.size());
}
System.debug(numberOfContacts);


Share This:    Facebook Twitter

Apex: Get all required fields of an sObject

Map<String, Schema.SObjectType> m  = Schema.getGlobalDescribe();
Schema.SObjectType s = m.get('Contact');
Schema.DescribeSObjectResult r = s.getDescribe();
Map<String,Schema.SObjectField> fields = r.fields.getMap();

for(String field : fields.keyset()) {
    Schema.DescribeFieldResult describeResult = fields.get(field).getDescribe();
    if (describeResult.isCreateable()  && !describeResult.isNillable() && !describeResult.isDefaultedOnCreate()) {
        System.debug(field);
    }
}


Share This:    Facebook Twitter

Saturday, December 2, 2017

Total Pageviews

My Social Profiles

View Sonal's profile on LinkedIn

Tags

__proto__ $Browser Access Grants Accessor properties Admin Ajax AllowsCallouts Apex Apex Map Apex Sharing AssignmentRuleHeader AsyncApexJob Asynchronous Auth Provider AWS Callbacks Connected app constructor Cookie CPU Time CSP Trusted Sites CSS Custom settings CustomLabels Data properties Database.Batchable Database.BatchableContext Database.query Describe Result Destructuring Dynamic Apex Dynamic SOQL Einstein Analytics enqueueJob Enterprise Territory Management Enumeration escapeSingleQuotes featured Flows geolocation getGlobalDescribe getOrgDefaults() getPicklistValues getRecordTypeId() getRecordTypeInfosByName() getURLParameters Google Maps Governor Limits hasOwnProperty() Heap Heap Size IIFE Immediately Invoked Function Expression Interview questions isCustom() Javascript Javascript Array jsForce Lightning Lightning Components Lightning Events lightning-record-edit-form lightning:combobox lightning:icon lightning:input lightning:select LockerService Lookup LWC Manual Sharing Map Modal Module Pattern Named Credentials NodeJS OAuth Object.freeze() Object.keys() Object.preventExtensions() Object.seal() Organization Wide Defaults Override PDF Reader Performance performance.now() Permission Sets Picklist Platform events Popup Postman Primitive Types Profiles Promise propertyIsEnumerable() prototype Query Selectivity Queueable Record types Reference Types Regex Regular Expressions Relationships Rest API Rest Operator Revealing Module Pattern Role Hierarchy Salesforce Salesforce Security Schema.DescribeFieldResult Schema.DescribeSObjectResult Schema.PicklistEntry Schema.SObjectField Schema.SObjectType Security Service Components Shadow DOM Sharing Sharing Rules Singleton Slots SOAP API SOAP Web Services SOQL SOQL injection Spread Operator Star Rating stripInaccessible svg svgIcon Synchronous this Token Triggers uiObjectInfoApi Upload Files VSCode Web Services XHR
Scroll To Top