Posts

Showing posts with the label save

Salesforce Fact #760 | Territory Assignment rule on account save

Image
There is a checkbox 'Evaluate this account against territory rules on save' on the Account layout to run the territory assignment rules. In order to make the checkbox visible, go to Account Page Layout -> Layout Properties -> Select show on edit page. It can also be marked as checked by default if the option 'Default' is selected. Whenever an account is assigned to a territory using the territory assignment rule, an AccountShare row is created with RowCause='Territory'. Reference:  https://help.salesforce.com/s/articleView?id=000385116&type=1 Attached are the screenshots.

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.