Posts

Showing posts from October, 2021

Salesforce Fact #225 | List copy in flow

Image
Unlike apex, Collections in flow follow deep copy paradigm while one list is assigned to another. In this example, we have two lists accList1 & accList2. accList1 is populated with the result of Get Records element for Account object, then accList2 is populated with the values of accList1. Now when we remove the first element from accList1, the same is not changed in accList2. Attached are the screenshots.

Salesforce Fact #224 | AND OR in same SOQL

Image
Whenever we are using both AND & OR operator in SOQL, we should always ensure proper parenthesis is in place to define the priority. But do not worry if you forget to include parenthesis, you would get error be it in Developer console or be it in apex class. Attached are the screenshots.

Salesforce Fact #223 | Modifying collection during iteration itself

Image
Do you know we can make changes in the collection which is used in the SOQL filter during the iteration itself. Suppose, we have a set of account names and we would like to find out the unique ones from the set. In this case, we can iterate over the SOQL result and at the same time remove the name which is returned in the current iteration. This is quite efficient as the need for using an extra collection to store the unique values is removed. Attached are the screenshots.

Salesforce Fact #222 | Parent record data in delete trigger

Image
Suppose we need to get parent record data in the delete trigger of child record. In that case, it is only available using SOQL from before delete trigger. The after delete trigger won't return any data from SOQL. Attached are the screenshots.

Salesforce Fact #221 | Access record without having access to record type

Image
Do you know you can access a record of a particular record type even if you don't have the record type assigned through your profile or permission set. You can even edit the record if it is shared with read/write access. In this example, we have two users Tom & John. Tom is assigned to record type RT1 while John is assigned to record type RT2 for Account object. Now Tom creates an account record and shares the same with John with R/W access. Now even if John is not assigned the record type RT1, he can read and edit that particular record. Attached are the screenshots.

Salesforce Fact #220 | Get trigger details using screen flow

Image
Suppose we want to get the details of Apex triggers for a particular object. Now instead of going to each object from object manager or doing SOQL multiple times, we can have a screen flow serving the purpose quickly. We can design a screen flow which will take the input object name for which we want to get the trigger details and then we will use a get records element to get the data and finally format the data using text templates. Attached are the screenshots.

Salesforce Fact #219 | Child data unavailable in after delete SOQL

Image
If we have a trigger on child object then in case of before delete trigger we get the data from child record in inner SOQL query, but in case of after delete it is not available anymore even if we consider trigger.old. Note: Please do not follow this coding as it is only for demonstration purpose and trigger best practices can be implemented. Attached are the screenshots.    

Salesforce Fact #218 | Blank picklist value is actually NULL

Image
Whenever we are setting any picklist field value to blank, it will get stored in database as NULL. So we need to be careful while processing this data after fetching from database. In this example, we are creating an account in a test method with type as blank, and populating blank using single quotes instead of NULL. Now after we fetch the data from the database it is NULL, not blank. Attached are the screenshots.

Salesforce Fact #217 | Delete debug log from screen flow

Image
Suppose we need to delete the debug log for certain user. Now we cannot do delete DML on ApexLog records from apex. Well, Salesforce flow again to the rescue. We can have a screen flow to select the user and start time, based on which we can use delete records element to delete the debug logs. Attached are the screenshots.