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
Shruti NigamShruti Nigam 

Hello Actually I want to perform this scenario Create an Assignment_History__c record whenever an Account’s BillingPostalCode is changed. All fields should be populated.

Field NameField TypeDescription
Previous OwnerLookup (User)The prior sales rep assigned to this Account
New OwnerLookup (User)The new sales rep assigned to this Account
Previous TerritoryLookup (Territory__c)The matching Territory__c record for the prior zip code
New TerritoryLookup (Territory__c)The matching Territory__c record for the new zip code
AccountMaster-Detail (Account)The related Account record
Changed ByLookup (User)The user who changed the BillingPostalCode
mukesh guptamukesh gupta
Hi shruti 

you can use porcess builder to cover your task, https://help.salesforce.com/articleView?id=000220643&language=en_US&type=1

if you have any issue,Please tell me.

Kindly MARK AS A BEST ANSWER!!if the reply was helpful.


Regards
Mukesh


 
Shruti NigamShruti Nigam
Ya you are right but i want to perform this scenario in trigger can you please help me with that
Shubham_KumarShubham_Kumar
Hi Shruti

If you want to create Assignment_History__c  on the update only then here`s the sample code.
You can start with this. If you have any further questions, let me know.
trigger createAssignmentRec on Account(after update){
	List<Assignmnet> recToUpdate = new List<Assignment>();
	for(Account acc : trigger.new ){
		if(acc.BillingAddress != trigger.oldMap.get(acc.id).BillingAddress && acc.BillingAddress != null){
			Assignment_History__c ah = new Assignment_History__c ();
			//create Your Assignment_History__c record
			recToUpdate.add(ah);
		}
	}
	if(recToUpdate.size()>0){
		insert recToUpdate;
	}
	
}
P.S.: Mark this as Best Answer if this reply helped you.
 
Thanks
Shubham Kumar
Shubham_KumarShubham_Kumar
Hi 
My bad, i didn`t  explain it clearly. You have to use API of Billing Address.
Please try this Code.
trigger AssignmentHistory5 on Account (after update) {
    List<Assignment_History__c> recUpdate= new List<Assignment_History__c>();
    for(Account acc : trigger.new ){
      	if((acc.BillingStreet != trigger.oldMap.get(acc.id).BillingStreet && acc.BillingStreet!= null) || 
            (acc.BillingCity != trigger.oldMap.get(acc.id).BillingCity && acc.BillingCity!= null)|| 
           (acc.BillingState != trigger.oldMap.get(acc.id).BillingState && acc.BillingState!= null) ||
           (acc.BillingPostalCode != trigger.oldMap.get(acc.id).BillingPostalCode && acc.BillingPostalCode!= null) ||           (acc.BillingLatitude != trigger.oldMap.get(acc.id).BillingLatitude && acc.BillingLatitude!= null) ||
            (acc.BillingLongitude != trigger.oldMap.get(acc.id).BillingLongitude && acc.BillingLongitude!= null))
{
            Assignment_History__c a = new Assignment_History__c ();
            a.Name='XYZ';
            a.PreviousOwner__c=acc.OwnerId;
            recUpdate.add(a);
        }
    }
    if(recUpdate.size()>0){
        insert recUpdate;
    }
    
}

 
Shruti NigamShruti Nigam
Ya you were right now code is working properly
Thanks Shubham
Shubham_KumarShubham_Kumar
Always Happy to help.
Shruti NigamShruti Nigam
Can anyone please help me for how to get previous owner and previous territory field for above scenario
As im getting only new owner in my data
Here is my code:
trigger AssignmentHistory5 on Account (before update,after update)
{
    List <Assignment_History__c> assign = new List <Assignment_History__c> ();
    for(Account a: Trigger.new) 
    {
        if((a.BillingPostalCode!= null) && (a.BillingPostalCode != Trigger.oldMap.get(a.Id).BillingPostalCode))
        { 
            Assignment_History__c assign1 = new  Assignment_History__c ();
            assign1.Account__c = a.Id;
            assign1.NewOwner__c = a.OwnerId;
            assign.add(assign1);
            System.debug(assign1);
        }
    }
            insert assign;
  
 }
manish m 10manish m 10
This site should be awaard winning
Download Hindi marvel Movies (https://hotmarvelmovies.blogspot.com/)  and also download All hindi marvel movies in HD (https://moviesmarveldownload.blogspot.com/) and also download marvel movies latest (https://allmarvelmoviesdown.blogspot.com/)

Downalod black panther in hindi and HD (https://moviesmarveldownload.blogspot.com/2019/10/black-panther-2018-dual-audio-in-hindi-download-watch-online.html) thor ragnarok Download in Hindi and HD (https://moviesmarveldownload.blogspot.com/2019/10/thor-ragnarok-2017-dual-audio-hindi-dh-download.html)
manish m 10manish m 10
I have found best site to read song lyrics

Moscow Suka Lyrics – Honey Singh, Neha Kakkar (https://songslyricsfree.com/moscow-suka-lyrics-yo-yo-honey-singh/
 Latest hindi Song Lyrics
Hindi Song Lyrics for free
manish m 10manish m 10
I have found
Santa and banta Hindi funny Jokes (https://www.funnyjokesnew.com/santa-banta-jokes/)
REad Hindi funny jokes (https://www.funnyjokesnew.com/)

Rtmnu Question papers (https://eonlinelearners.com/)
Dadi Prak DadiDadi Prak Dadi
Shruti you can access the old Account Owner and Territory using Trigger.OldMap

trigger AssignmentHistory5 on Account (before update,after update)
{
    List <Assignment_History__c> assign = new List <Assignment_History__c> ();
    for(Account a: Trigger.new) 
    {
        if((a.BillingPostalCode!= null) && (a.BillingPostalCode != Trigger.oldMap.get(a.Id).BillingPostalCode))
        {   
            Assignment_History__c assign1 = new  Assignment_History__c ();
            assign1.Previous_Owner__c = Trigger.oldMap.get(a.ID).OwnerId;
            assign1.Previous_Territory__c = Trigger.oldMap.get(a.ID).Territory__c;
            assign1.Account__c = a.Id;
            assign1.NewOwner__c = a.OwnerId;
            assign.add(assign1);
            System.debug(assign1);
        }
    }
            insert assign;
  
 }