Skip to main content
edited tags
Link
Derek F
  • 64.1k
  • 15
  • 55
  • 104
Source Link

What results are matched with which filter in SOQL Filters

I have before insert trigger on account and i want to set primary contact lookup(custom field on account) which match with account name.

For example, if account name with 'Tony Stark' is inserting then i have to find contact name with 'Tony Stark' and add the lookup in to primary contact.

For this problem i am using soql query with like filter.

List<Contact> lstContact = [SELECT id, Name FROM contact WHERE Name like '%acc.Name%'];

My question is how can i do it for multiple accounts if there is bulk upload?

Do i have to iterate for each and every account.name and update the lookup?

It will cost more SOQL queries.