• ShiviS
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Requirement: When a Billing Address is modified, get the new Postal Code. Then check which Contacts on the Account are outside that Postal Code. If 1 or more Contacts are outside of the Postal Code, mark Out_of_Zip as TRUE.

I wrote this trigger on account object:

 trigger Q2 on Account (after update) {
    List<id> aid=new list<id>();
    List<Contact> c=new List<Contact>();
    
    List<id> aidd=new list<id>();
    List<account> az=new list<account>();
    List<account> acfinal=new List<account>();
    
    for(Account a1:trigger.new){
        aid.add(a1.id);
    }
    c=[select id,MailingPostalCode,Accountid from contact where accountid in :aid];
    for(Account aa:Trigger.new){
        for(contact con:c){
            if(con.Accountid==aa.id && con.MailingPostalCode!=aa.BillingPostalCode){
                aidd.add(aa.id);
            }
        }
    }
    az=[select id, Out_of_Zip__c from account where id in :aid];
    for(account al:az){
        al.Out_of_Zip__c=true;
        acfinal.add(al);
    }
    update acfinal;
}

When I am changin the postal code on the account object, It's giving the below error:

Q2: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0012v00003EsSb5AAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Q2: maximum trigger depth exceeded Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate: [] Trigger.Q2: line 27, column 1

Kindly let me know why is this happening? I am a beginner to coding.
  • April 11, 2021
  • Like
  • 1
Requirement: When a Billing Address is modified, get the new Postal Code. Then check which Contacts on the Account are outside that Postal Code. If 1 or more Contacts are outside of the Postal Code, mark Out_of_Zip as TRUE.

I wrote this trigger on account object:

 trigger Q2 on Account (after update) {
    List<id> aid=new list<id>();
    List<Contact> c=new List<Contact>();
    
    List<id> aidd=new list<id>();
    List<account> az=new list<account>();
    List<account> acfinal=new List<account>();
    
    for(Account a1:trigger.new){
        aid.add(a1.id);
    }
    c=[select id,MailingPostalCode,Accountid from contact where accountid in :aid];
    for(Account aa:Trigger.new){
        for(contact con:c){
            if(con.Accountid==aa.id && con.MailingPostalCode!=aa.BillingPostalCode){
                aidd.add(aa.id);
            }
        }
    }
    az=[select id, Out_of_Zip__c from account where id in :aid];
    for(account al:az){
        al.Out_of_Zip__c=true;
        acfinal.add(al);
    }
    update acfinal;
}

When I am changin the postal code on the account object, It's giving the below error:

Q2: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0012v00003EsSb5AAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Q2: maximum trigger depth exceeded Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate: [] Trigger.Q2: line 27, column 1

Kindly let me know why is this happening? I am a beginner to coding.
  • April 11, 2021
  • Like
  • 1
Requirement: When a Billing Address is modified, get the new Postal Code. Then check which Contacts on the Account are outside that Postal Code. If 1 or more Contacts are outside of the Postal Code, mark Out_of_Zip as TRUE.

I wrote this trigger on account object:

 trigger Q2 on Account (after update) {
    List<id> aid=new list<id>();
    List<Contact> c=new List<Contact>();
    
    List<id> aidd=new list<id>();
    List<account> az=new list<account>();
    List<account> acfinal=new List<account>();
    
    for(Account a1:trigger.new){
        aid.add(a1.id);
    }
    c=[select id,MailingPostalCode,Accountid from contact where accountid in :aid];
    for(Account aa:Trigger.new){
        for(contact con:c){
            if(con.Accountid==aa.id && con.MailingPostalCode!=aa.BillingPostalCode){
                aidd.add(aa.id);
            }
        }
    }
    az=[select id, Out_of_Zip__c from account where id in :aid];
    for(account al:az){
        al.Out_of_Zip__c=true;
        acfinal.add(al);
    }
    update acfinal;
}

When I am changin the postal code on the account object, It's giving the below error:

Q2: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0012v00003EsSb5AAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Q2: maximum trigger depth exceeded Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate Account trigger event AfterUpdate: [] Trigger.Q2: line 27, column 1

Kindly let me know why is this happening? I am a beginner to coding.
  • April 11, 2021
  • Like
  • 1