+ Start a Discussion
Mohd NabeelMohd Nabeel 

Create a field on Account called “Out_of_Zip”, checkbox, default off 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 P

i am new to salesforce and i am trying to achieve this task... i get the question that what it is saying, but not able to get it how will i achieve this... 
Ajay K DubediAjay K Dubedi
Hi Mohd Nabeel,

I have understood your requirements and made a solution for it.
I have made a trigger. But to achieve this you should have an Account with more than 2 contacts and also a custom checkbox field in Account object.
If you don't know how to make custom fields then prefer this link-

https://help.salesforce.com/articleView?id=adding_fields.htm&type=5 (https://help.salesforce.com/articleView?id=adding_fields.htm&type=5)

Make sure initially, the  Billing postal code for the account and mailing postal code for contacts are similar and not empty.
Trigger Test_Out_of_Zip on account (after update) {

  public static boolean flag=true;
If(flag==true) {
  account acc = [select id,Out_of_Zip,BillingPostalCode from account where id in : trigger.new];
  List<contact> conList = [select id, name,MailingPostalCode from contact where accoundId in :   acc];

List<contact> conListNew = new List<contact>();

for (contact con : conList)
  if(acc.BillingPostalCode != con.MailingPostalCode)


  acc.Out_of_Zip = true;


update acc;


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
Akash KainturaAkash Kaintura
It's not working do i need to make an extra Mailing Postal code field in contact ?