You need to sign in to do that
Don't have an account?
cbro
Trigger Compile Error "left angle bracket" (too many SOQL Queries fix, as well)
Can anyone help me to fix this trigger?
What am I missing here?
Error: Compile Error: expecting a left angle bracket, found '>' at line 3 column 32
trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update){ Set <Id> headerIds = new Id<Set>(): List <Contract_Line__c> contractLines = new List <Contract_Line__c>(); List <Contract_Line__c> updateContractUpdate = new List <Contract_Line__c>(); //go through trigger items and add related headers to a set for(Contract_Line__c c: Trigger.new){ headerIds.add(c.Contract_Header_LOOKUP__c) } //go through headers and get account Ids List <Contract_Header__c> headers = [Select Id, Account__c FROM Contract_Header__c WHERE Id IN: headerIds]; //match header accounts to cl accounts List <Contract_Line__c> contractLines = [Select Id, Contract_Header_LOOKUP__c FROM Contract_Line__c WHERE Id IN: Trigger.newMap.keySet() AND Account__c IN: contractHeaderAccts]); //copy the record id to contract header lookup if(contractLines.size()>0 && headers.size()>0){ for(Contract_Line__c cl: contractLines){ for(Contract_Header__c ch: headers){ cl.Contract_Header_LOOKUP__c = ch.Id; updateContractUpdate.add(cl); } } } if(updateContractUpdate.size()>0){ update updateContractUpdate; } }
This was my original code, but I was getting too many SOQL queries (not enough filters) when uploading data, so I changed it (with lots of help) to the above:
trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before insert, before update) { for (Contract_Line__c cl: Trigger.new) { if(cl.Contract_Header_LOOKUP__c == Null) { cl.Contract_Header_LOOKUP__c = [SELECT id FROM Contract_Header__c WHERE Name =: cl.Contract_Header__c].id ; } } }
Please notice the second line of your code:-)
All Answers
Please notice the second line of your code:-)
After a few more tweaks, here is the final code. I had to change it to after insert and after update, as I was receiving errors in trying to refer to a null object when trying to run this before insert.
I needed to add filters to stop the SOQL queries from going over the limit.
Instead of pulling back ALL Contract Header records, I only pulled back records that matched the Account ID for the Contract Lines.
In our instance, Contract_Header__c.Account__c will always match Contract_Line__c.Account__c, so that is how I fixed the issue of too many SOQL Queries.