Posts

Showing posts from July, 2019
Image
Related reference Fields Value in sObject SOQL In Dynamic SOQL we create query string using Apex code at run time and use Database.Query method to fetch the results. example:  String queryString = ' SELECT Id, Name, AccountId FROM Contact LIMIT 1'; sObject result = Database.query(queryString); above query will return me a contact information, if I wanted to access record's Name I can access it using sObject get() method i.e. result.get('Name') will give me Name value. Output: But the real challenge we will face when you try to access fields value from related object field, i.e. if you try to access Account.AnnaualRevenue you will get an exception 'System.SObjectException: Invalid field Account.AnnualRevenue for Contact'. To fix this we we will use getSObject() method to traverse the relationship. below code will traverse the relationship and get you the value: References: sObject Class , String Class , Martin Borthiry
Image
Asynchronous Apex Triggers In Summer 19 release Salesforce introduce a new feature to process data using a combination of 'Asynchronous Apex Triggers' and Change Data Capture. Any DML on Salesforce records causes platform to start a series of calculations, run business logic and database updates, all these are called as an Apex Transactions. You can reduce the Apex transaction time to complete the business logic and limit constraints by decoupling resource-intensive, non-transactional logic from database transaction and execute asynchronously.  Asynchronous Apex triggers are change event triggers that run asynchronously after a database transaction is completed. They are ‘after-insert’ triggers and can be defined with the after insert keywords. They can be created the same way we create regular Apex triggers. You set the trigger to use a change event object instead of an sObject. The change event object name is suffixed with ChangeEvent. For example, Account change e...