Skip to content

Instantly share code, notes, and snippets.

@mailtoharshit
Created February 25, 2014 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mailtoharshit/9219539 to your computer and use it in GitHub Desktop.
Save mailtoharshit/9219539 to your computer and use it in GitHub Desktop.
if (Trigger.isUpdate) {
//Create a list of old and new Values
public List<Sales_Support_Request__c> oldList = new List<Sales_Support_Request__c>();
public List<Sales_Support_Request__c> newList = new List<Sales_Support_Request__c>();
//populate both the list
oldList=Trigger.New;
newList=Trigger.old;
//lets create two maps to compare
Map<Id, Sales_Support_Request__c> oldMap = new Map<Id, Sales_Support__c>();
Map<Id, Sales_Support_Request__c> newMap = new Map<Id, Sales_Support__c>();
//Populate the Map iterating through List
// use put method to add values to map
for(Sales_Support_Request__c rec : oldList)
oldMap.put(rec.id,rec);
for(Sales_Support_Request__c rec : newList)
oldMap.put(rec.id,rec);
//Now we are loaded with data we needed
//Now lets say you want to compare the old account with new account
//here is how you do it while looping through new map
for(Sales_Support_Request__c rec : newList)
{
Sales_Support_Request__c createSSR = new Sales_Support_Request__c();
//get old value from old map
if(rec.Account__c != oldMap(rec.id).Account__c)
{
//if the account is changed then set account
createSSR.Account=rec.Account__c;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment