function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jadenjaden 

Trigger limits

Hi,

 

I am trying to be mindful of trigger limits but I am having difficulty getting something working.

 

I am creating a list of the Territory Zip recs I need and then I need to find all accounts with that ip code.. The Territory list is fine.  How can I build the account list without putting it into the for loop? Below is what I am trying for Accoint and neither seems to be correct. 

 

set<ID> ids = Trigger.oldMap.keyset();

list<Territory_Zip_Code__c> tzcRecs = [SELECT Id, Name, GroupId__c FROM Territory_Zip_Code__c WHEREID in :ids]; 

 

//list<Account> AccountZipRecs = [SELECT id, BillingPostalCode FROM Account WHERE BillingPostalCode in :tzcRecs.Name ];

 

list<Account> AccountZipRecs = [SELECT id, BillingPostalCode FROMAccountWHERE BillingPostalCode in tzcRecs.Name ];

 

Any help appreciated,

Best Answer chosen by Admin (Salesforce Developers) 
jadenjaden

Sorry, I tried to clean up open requests and missed this one.  I did get things working thank you for help.

All Answers

Rahul SharmaRahul Sharma

a joint query will work here.

 

I'm not much familiar with fields of your object, so i suggest to try this:

If it runs correctly, it will give you all the desired accounts.
 

list<Account> AccountZipRecs = [SELECT id, BillingPostalCode FROM Account WHERE BillingPostalCode in (SELECT Name FROM Territory_Zip_Code__c WHERE ID in :Trigger.oldMap.keyset()) ];

Hope it helps.

jadenjaden

Thanks, I tried that but get the following error:

 

semi join sub selects can only query id fields, cannot use: 'Name' 

 

so not sure how to get around this,

Rahul SharmaRahul Sharma

Ohh, it seems there's no relation between Account and Territory_Zip_Code__c, right?

It would be helpful for us to help us, if you post whole trigger.

jadenjaden

Sorry, I tried to clean up open requests and missed this one.  I did get things working thank you for help.

This was selected as the best answer