+ Start a Discussion
Jyosi jyosiJyosi jyosi 

@future method to use Trigger.Old and Trigger.New

Hello Everyone,

I need to compare the Trigger.Old and Trigger.new Values in Apex Callout 
My code goes here 

if(Trigger.IsUpdate && Trigger.isBefore)

public static void JcoreAdd(Set<Id> contactIdSet)
        Set<Id> TerminateCntId= new Set<Id>();
        Set<Id> RepIdsValue= new Set<Id>();
        List<Id> CntListIds= new List<Id>();
        List<contact> TerminateCntList= new List<contact>();
             String   RepHireDate;
          Datetime HireDate;
          Datetime Birthdate;
          String   BithdateRep;
          String   MobileNumber1;
          String   MobileNumber;
          String   HomeNumber1;
          String   HomeNumber;
          Datetime QAMDSPStartDate;
          Datetime QAMDSPEndDate;
          String  QAMDSPStartDateConversion;
          String  QAMDSPEndDateConversion;
          Datetime QCCDSPStartDate;
          Datetime QCCDSPEndDate;
          String QCCDSPStartDateConversion;
          List<Contact>  contactUpdate= new List<Contact>();
          String prospectRecType = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Rep').getRecordTypeId();
          List<Contact> LstCntQuery=[Select Id,Name,CRD__c,FirstName,LastName,Middle_name__c,Gender__c,Address_Type__c,
                                            OtherCity,OtherPostalCode,OtherState,OtherStreet ,Birthdate,Rep_Status__c,QAM_DSP__r.Start_Date__c,QAM_DSP__r.Term_Date__c,
                                           QCC_DSP__c,RecordTypeId ,QAM_DSP_End_Date__c,QCC_DSP_Start_Date__c,QAM_DSP_Start_Date__c,Salutation,Term_Date__c,Start_Date__c,Jcore_Status__c,LastModifiedDate,HomePhone,Phone,OtherPhone
                                            from Contact where Id IN:contactIdSet];

I need to compare the fields QAM_DSP__r.CRD__C

Here is breif why i am going for that 
before update i am trying to update this value in another system.
I have Rep tied to a Manager 
First call out takes the Manager Name,Start date  and Insert the values.
after few days the Manager changes that time the Second Manager start date should be equal to FirsrManger End Date .
So i thought to compare the new an old values  
based on new and old values i need to control to populate the End Date Accordingly.

Please help me out.


Without fully understanding your situation, my quick reply would be that @future methods can accept primitive values, arrays of primitives or collections of primitives. What this means for you is that you can pass a map of Ids and the old values to the @future method, something like this:
static void DoSomething(Map<Id, String> oldValuesByRecordId){
    for(MyObject__c m : [SELECT ... WHERE Id IN :oldValuesByRecordId.keySet()]){
        if(m.MyField__c != oldValuesByRecordId.get(m.Id)){

Future Annotation (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm" target="_blank)
Primitive Data Types (https://www.salesforce.com/developer/docs/api/Content/primitive_data_types.htm" target="_blank)