function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Neeraj Sharma 103Neeraj Sharma 103 

Hi Everyone Please Help Me out For this Scenario When an Account's BillingPostalCode is Changed

Hi  i am new in Salesforce
I am Beginner
So Please Help me Out from this Scenario

When an Account's Billing Zip/Postal Code field value is changed and entered new value then
this situation will occur
1.Change the Account Owner to the Sales Representative assigned to the new zip code(Sales Representative is users that will be in another custom Object Terriotry object its a lookup )
2.Change the Owner Field of all the Account's Contacts to the same Sales Representative
3.Change the Owner Field of all the Account's Open Opportunities to the Same Sales RepresentativeIn this Image this are the Sales Representative in Custom Object TerritoryIn this Image This are the Custom fileds of territory objectSo Please Help Me out From this Scenario How to Start From where i dont know 

Please Reply As Soon Possible

Thanks
Neeraj Sharma
Best Answer chosen by Neeraj Sharma 103
Meghna Vijay 7Meghna Vijay 7
Hi Neeraj,

1. Change the Account Owner to the Sales Representative assigned to the new zip code(Sales Representative is users that will be in another custom Object Terriotry object its a lookup ) :- Before update event
2. and 3. After Update event
 
trigger AccountTrigger on Account(before update, after update) {
   AccountTriggerHandler.onupdate(Trigger.New, Trigger.oldMap);
}

public class AccountTriggerHandler {
   public static void onUpdate(List<Account> newAccList, Map<Id, Account> accMap) {
     for(Account acc : newAccList) {
       if(acc.PostalCode != accMap.get(acc.Id).PostalCode) {
          // write your code
}
}
}
}

Hope it helps, if it does mark it as solved.

Thanks
 

All Answers

kavya mareedukavya mareedu
Are you trying to write a trigger for this scenerio?? 
Neeraj Sharma 103Neeraj Sharma 103
Hi kavya mareedu
Yes But how to write trigger for this scenario so please help me out 
Neeraj Sharma 103Neeraj Sharma 103
When i changed postal code of Accounts then the owner of that  Account will be changed automatically and assign to the Sales Represenative and the contacts of that account owner of the contact also changed and assigned to the Sales Representative this scenario also same for opportunity
Meghna Vijay 7Meghna Vijay 7
Hi Neeraj,

1. Change the Account Owner to the Sales Representative assigned to the new zip code(Sales Representative is users that will be in another custom Object Terriotry object its a lookup ) :- Before update event
2. and 3. After Update event
 
trigger AccountTrigger on Account(before update, after update) {
   AccountTriggerHandler.onupdate(Trigger.New, Trigger.oldMap);
}

public class AccountTriggerHandler {
   public static void onUpdate(List<Account> newAccList, Map<Id, Account> accMap) {
     for(Account acc : newAccList) {
       if(acc.PostalCode != accMap.get(acc.Id).PostalCode) {
          // write your code
}
}
}
}

Hope it helps, if it does mark it as solved.

Thanks
 
This was selected as the best answer
Neeraj Sharma 103Neeraj Sharma 103
Hi @Meghna Vijay7
I dont know what i write in Section of //write your code
can you send me full code of trigger i will try my codeor trigger but it will not working
so please give me full code of your trigger to i understand them and manage the code according to my scenario