Posts

Showing posts with the label method

Salesforce Fact #810 | Call parent component method in child LWC

Image
In order to call parent component's method in child LWC component, we can pass the method as a public property from parent to child and then invoke the same in child component. Reference:  https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000C5ddmSAB Attached are the screenshots.

Salesforce Fact #783 | add() method error

Image
While using the add() method to add element in a list at a particular index, we need to be careful. Unlike other programming languages, we will encounter error if the list is empty. Attached is the screenshot.

Salesforce Fact #753 | Save one for loop using clone() method

Image
Suppose we need to find out which accounts have related contacts or no related contacts in the apex code.  Now as per the usual logic, we would fetch the data from contact object based on the AccountIds which would give us the count of accounts having related contacts. And after that, we would run another loop to iterate over the master account list and check which one does not have any related contact. Well, we can use the clone() method of Set class which would help us to save one loop. Attached is the screenshot. Note: The SOQL and list lengths are only for demonstration purpose. As per the best practice, SOQLs need to be as much as selective with proper access checks to retrieve only the intended records.