You need to sign in to do that
Don't have an account?
Dipthi
Trigger on updating Account field value based on Contact - Struck plz suggest
Hi Awesome coders,
I have a checkbox field 'Out of Zip' on Account. When an Account's 'Billing Postal code' field is updated, check its Contacts 'mailing postal code'. If more than one contacts 'mailing postal code' field is not matching with Account then 'Out of Zip' field on Account should be turned True.
Plz correct my code in bold
trigger AccountOutOfZip on Account (After Update) {
// Adding record Id's of Accounts whose postal code is updated
Set<Id> AccIdSet = new Set<Id>() ;
for(Account acc : Trigger.new) {
Account oldAcc = Trigger.oldMap.get(acc.Id);
If(acc.billingpostalcode != oldAcc.billingpostalcode ) {
AccIdSet.Add(acc.Id) ;
}
}
List <Account> AccUpdateList = New List<Account>();
If(AccIdSet.size() > 0) {
Account[] accList = [SELECT Id from Account where Id IN :AccIdSet] ;
Contact[] conList = [SELECT Id,AccountId from Contact where AccountId IN :AccIdSet] ;
for(Account a : accList) {
for(Contact c : conList) {
If(a.billingpostalcode != c.MailingPostalCode) {
// a.Out_Of_Zip__c = True ;
AccUpdateList.add(a.Id = c.AccountId, a.Out_Of_Zip__c = True) ;
}
}
}
If(!AccUpdateList.isEmpty()) {
update AccUpdateList ;
}
}
I have a checkbox field 'Out of Zip' on Account. When an Account's 'Billing Postal code' field is updated, check its Contacts 'mailing postal code'. If more than one contacts 'mailing postal code' field is not matching with Account then 'Out of Zip' field on Account should be turned True.
Plz correct my code in bold
trigger AccountOutOfZip on Account (After Update) {
// Adding record Id's of Accounts whose postal code is updated
Set<Id> AccIdSet = new Set<Id>() ;
for(Account acc : Trigger.new) {
Account oldAcc = Trigger.oldMap.get(acc.Id);
If(acc.billingpostalcode != oldAcc.billingpostalcode ) {
AccIdSet.Add(acc.Id) ;
}
}
List <Account> AccUpdateList = New List<Account>();
If(AccIdSet.size() > 0) {
Account[] accList = [SELECT Id from Account where Id IN :AccIdSet] ;
Contact[] conList = [SELECT Id,AccountId from Contact where AccountId IN :AccIdSet] ;
for(Account a : accList) {
for(Contact c : conList) {
If(a.billingpostalcode != c.MailingPostalCode) {
// a.Out_Of_Zip__c = True ;
AccUpdateList.add(a.Id = c.AccountId, a.Out_Of_Zip__c = True) ;
}
}
}
If(!AccUpdateList.isEmpty()) {
update AccUpdateList ;
}
}
Hi Anudeep,
I am getting error on Line 20 : AccUpdateList.add(a.Id = c.AccountId, a.Out_Of_Zip__c = True) ;
Error : Method does not exist or incorrect signature: void add(Id, Boolean) from the type List<Account>