You need to sign in to do that
Don't have an account?
carramrod
Apex Class/Trigger hitting limits -need a quick lookover
i've got a trigger calling this, but it bombs everytime an account has over 20 contacts. I want to incorporate some custom objects similarly too, but i'm hitting limits.
I'm using this for an integration and need to fire an update on every child record (contact, custom object, etc..) when an account is saved. If i daisy chain the updates to other objects to other triggers, can i get around this limitation?
for instance: assuming what i have below can be fixed and i can update more than 20 contacts in one call, account trigger modifies contacts, contacts trigger modifies custom object a, custom object a modifies custom object b.
public static void fireUpdatesOnChildObjects(Account[] accs){
for (Account a:accs){
//change status of this object.
if (a.Toggle_Update__c == true){
a.Toggle_Update__c = false;
}
else{
a.Toggle_Update__c = true;
}
//fire updates on contacts
Contact[] contacts = [SELECT ID,Toggle_Update__c FROM CONTACT WHERE AccountID =:a.ID];
for (Contact c:contacts){
if(c.Toggle_Update__c == true){
c.Toggle_Update__c = false;
}
else{
c.toggle_update__c = true;
}
update c;
}
//fire updates on Trip Logs
/*Trip_Log__c[] triplogs= [SELECT ID,Toggle_Update__c FROM Trip_Log__c WHERE Account__c =:a.ID];
for (Trip_Log__c t:triplogs){
if(t.Toggle_Update__c == true){
t.Toggle_Update__c = false;
}
else{
t.toggle_update__c = true;
}
update t;
}*/
}
}
I'm using this for an integration and need to fire an update on every child record (contact, custom object, etc..) when an account is saved. If i daisy chain the updates to other objects to other triggers, can i get around this limitation?
for instance: assuming what i have below can be fixed and i can update more than 20 contacts in one call, account trigger modifies contacts, contacts trigger modifies custom object a, custom object a modifies custom object b.
public static void fireUpdatesOnChildObjects(Account[] accs){
for (Account a:accs){
//change status of this object.
if (a.Toggle_Update__c == true){
a.Toggle_Update__c = false;
}
else{
a.Toggle_Update__c = true;
}
//fire updates on contacts
Contact[] contacts = [SELECT ID,Toggle_Update__c FROM CONTACT WHERE AccountID =:a.ID];
for (Contact c:contacts){
if(c.Toggle_Update__c == true){
c.Toggle_Update__c = false;
}
else{
c.toggle_update__c = true;
}
update c;
}
//fire updates on Trip Logs
/*Trip_Log__c[] triplogs= [SELECT ID,Toggle_Update__c FROM Trip_Log__c WHERE Account__c =:a.ID];
for (Trip_Log__c t:triplogs){
if(t.Toggle_Update__c == true){
t.Toggle_Update__c = false;
}
else{
t.toggle_update__c = true;
}
update t;
}*/
}
}
A couple of things you need to do to make it all work:
1. Pass a Trigger.newMap - a map of Accounts to your method as a second parameter from your trigger to the
2. Modify your code in the following way, so that DML statements are no longer inside a loop: