Created
February 25, 2014 22:42
-
-
Save mailtoharshit/9219539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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