Salesforce Fact #389 | Id comparison using SObject list in SOQL

We know that we can use trigger.new or trigger.old directly in SOQL when we are filtering based on recordId field. For example like below:

List<Account> accountList = [SELECT Name FROM Account WHERE Id IN :trigger.new];

Do you know you can use the same in other similar scenarios as well. This is quite efficient as it does not require a collection to store the Id and also avoids the iteration.

In this example, we need to find out the contact record details which are associated to accounts.

Attached are the screenshots.



 

 

Comments

Popular posts from this blog

Salesforce Fact #192 | Call batch apex from flow

Salesforce Fact #457 | Get current user role name in flow