You need to sign in to do that
Don't have an account?
How to resolve Trigger with TOO MANY SQL QUERIES:101 error.
Hi everyone,
i'm very much new to salesforce and i have written a trigger which has accomplished the task,but when there are many records its throwing an error: TOO MANY SQL QUERIES:101.
here is my trigger ,pls help me out with this issue
Trigger fieldupdate on External_Verification_Opinion__c (After insert,after update)
{
list<External_Verification_Opinion__c> evo = [SELECT id, Final_Opinion__c, RecordTypeId, Relationship_Form__c FROM External_Verification_Opinion__c where Final_Opinion__c=:'Approved' ];
for(External_Verification_Opinion__c e : evo)
{
list<Relationship__c> rf = [SELECT Id,Sent_For_External_Verification__c,Product_Family__c FROM Relationship__c where id=:e.Relationship_Form__c and Sent_For_External_Verification__c=:'yes'];
for(Relationship__c re : rf)
{
if((e.RecordTypeId=='012f00000004KhI') && ((re.Product_Family__c=='Saving Accounts') ||(re.Product_Family__c=='credit cards') || (re.Product_Family__c=='Mortgage') ||(re.Product_Family__c=='personal loans')))
{
re.Verifier__c=true;
update re;
}
if(((e.RecordTypeId=='012f00000004K2e') && (re.Product_Family__c=='Mortgage')) )
{
re.Technical_Valuator__c=true;
update re;
}
if(((e.RecordTypeId=='012f00000004K2j') && (re.Product_Family__c=='Mortgage')) )
{
re.Solicitor__c=true;
update re;
}
if((e.RecordTypeId=='012f00000004KhJ') && ((re.Product_Family__c=='credit cards') || (re.Product_Family__c=='Mortgage') ||(re.Product_Family__c=='personal loans')))
{
re.Credit_Agency__c=true;
update re; }
}
}
}
Hi
avoid Relationship__c object query inside the for loop.And try to fallow the best practise of the trigger.
{
ids.add(e.Relationship_Form__c );
recordtypess.add(e.recordtypeid);// i aded this so tht you can use in palce of e.recordtypeid now you can use set.contain(' ');
}
list<Relationship__c> rf = [SELECT Id,Sent_For_External_Verification__c,Product_Family__c FROM Relationship__c where id in: ids and Sent_For_External_Verification__c=:'yes'];
Your code will be something like this. Probably you need to amke sme adjustment in code, but this is an idea how you need to proceed.