Posts

Showing posts from January, 2017

Use Of addFields in ApexPages.StandardController

The add fields method helps developers specify fields for the standard controller to query in Visualforce pages. public AccountController(ApexPages.StandardController stdController){             this.controller = stdController;             List<String> fieldNamesList = new List<String>{Type,Industry};             stdController.addFields( fieldNamesList );             // stdController.addFields(new List<String>{'Name', 'TaxExemption__c', ' Industry '}); } Reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_addFields.htm

Lock Records Using Apex in Salesforce

Locking Statements In Apex, you can use FOR UPDATE to lock sObject records while they’re being updated to prevent race conditions and other thread safety problems. Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE]; Locking Consideration When records are locked by a client, that client can modify the record's field values in the database within the same transaction. Other clients must wait until the transaction is completed and the records are no longer locked before they can update the same records. However, other clients can still query the locked records. If a record is already locked by another client, a process will wait for a maximum of 10 seconds for the lock to be released before acquiring a new lock. If the wait exceeds 10 seconds, a QueryException is thrown. Similarly, if a record is locked by another client and the lock is not released within 10 seconds, a DmlException is thrown. If a client tries to modify a locked record, the update can succeed if the lock ...