You need to sign in to do that
Don't have an account?
Tillu
Unable to resolve error? please correct this code?
I am getting MarketMetricUpdate: System.LimitException: Too many SOQL 101 ....how to resolve this...can anyone correct below code.
Trigger MarketMetricUpdate on Market_Metrics__c(after insert,before update,after update)
{
Map<string,Market_Metrics__c> BusinessMap = new Map<string,Market_Metrics__c>();
set<id> Accountlist = new set<id>();
set<string> ZipList = new set<string>();
for(Market_Metrics__c b: Trigger.new)
{
if(String.IsNotBlank(b.Zip_Code__c) && String.IsNotBlank(b.SFDC_Account_Name__c))
{
BusinessMap.put(b.Zip_Code__c+b.SFDC_Account_Name__c,b);
Accountlist.add(b.SFDC_Account_Name__c);
zipList.add(b.Zip_Code__c);
}
}
Map<id,contact> ContactList = new Map<id,contact>([select id,Accountid,MailingPostalCode from Contact where Accountid IN : AccountList and MailingPostalCode IN:ZipList]);
List<contact> cUpdate = New List<Contact>();
for(Contact c : ContactList.values())
{
if(BusinessMap.get(c.MailingPostalCode+c.Accountid)!=null)
{
c.Market_Metrics__c = BusinessMap.get(c.MailingPostalCode+c.Accountid).id;
cUpdate.add(c);
}
}
if(cUpdate.size()>0)
update cUpdate;
}
Trigger MarketMetricUpdate on Market_Metrics__c(after insert,before update,after update)
{
Map<string,Market_Metrics__c> BusinessMap = new Map<string,Market_Metrics__c>();
set<id> Accountlist = new set<id>();
set<string> ZipList = new set<string>();
for(Market_Metrics__c b: Trigger.new)
{
if(String.IsNotBlank(b.Zip_Code__c) && String.IsNotBlank(b.SFDC_Account_Name__c))
{
BusinessMap.put(b.Zip_Code__c+b.SFDC_Account_Name__c,b);
Accountlist.add(b.SFDC_Account_Name__c);
zipList.add(b.Zip_Code__c);
}
}
Map<id,contact> ContactList = new Map<id,contact>([select id,Accountid,MailingPostalCode from Contact where Accountid IN : AccountList and MailingPostalCode IN:ZipList]);
List<contact> cUpdate = New List<Contact>();
for(Contact c : ContactList.values())
{
if(BusinessMap.get(c.MailingPostalCode+c.Accountid)!=null)
{
c.Market_Metrics__c = BusinessMap.get(c.MailingPostalCode+c.Accountid).id;
cUpdate.add(c);
}
}
if(cUpdate.size()>0)
update cUpdate;
}
The code I see shows a trigger on one object causing an update on another. This code is not by its nature recursive.
I agree that recursion is one of the possibilities to explore, but if you're seeing something I'm not, I'd love it if you would share.
Or do you just mean for Tillu to explore this as another possbility? For instance to look for code in the Contact trigger that is taking action upon Market_Metrics__c.
Tillu, one additional thing. Your trigger is firing on both before and after update. But you don't have anything in your code to control when this code executes. One quick fix that you might attempt is to remove "before update" from the events of this trigger to see if you get better results.
All Answers
Can you attempt this again trying to catch the debug log for this transaction? I would be more than willing to bet that this line:
update cUpdate;
is responsible for invoking another trigger down stream, which has the code that is the root cause.
Try to use recursion helper to get rid of this issue.
Regards,
- Harsha
The code I see shows a trigger on one object causing an update on another. This code is not by its nature recursive.
I agree that recursion is one of the possibilities to explore, but if you're seeing something I'm not, I'd love it if you would share.
Or do you just mean for Tillu to explore this as another possbility? For instance to look for code in the Contact trigger that is taking action upon Market_Metrics__c.
Tillu, one additional thing. Your trigger is firing on both before and after update. But you don't have anything in your code to control when this code executes. One quick fix that you might attempt is to remove "before update" from the events of this trigger to see if you get better results.
Cool.... you are right Peter..!
Regards,
- Harsha