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
Jyosi jyosiJyosi jyosi 

Call out (@Future) when the status is changed on contact

Hello Everyone,
I  am making a callout to external webservices ,I am not getting any error ,
Here is my problem ,When i update values on contact that wont value are not passing to external webservices.
Its passing the random records.
Below is my trigger code and apex Class

trigger Rephistorytracking on contact (after update,before update) {  
    RepTriggerHandlerclass contactHandler = new RepTriggerHandlerclass ();
    Jcoreutil    JcoreHandler= new Jcoreutil();
    if(Trigger.isAfter && Trigger.isUpdate) {
        contactHandler.onAfterUpdate(Trigger.New, Trigger.oldMap);
    }
    
    if(Trigger.IsAfter && Trigger.isUpdate)
    {
        contactHandler.onAftercontactUpdate(Trigger.New);
    }
     if(Trigger.IsUpdate && Trigger.isBefore)
    {
         Jcoreutil.JcoreAdd();
    }
 
}

###################APEX CLASS####################################


public class Jcoreutil {
     @future(callout=true)
     public static void JcoreAdd()
      {
        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 LicenseNumber;
         for( contact TerminateCntQuery :[Select Id,Name,CRD__c,FirstName,LastName,Middle_name__c,Gender__c,Address_Type__c,
                                          MailingStreet,MailingCity,MailingState,MailingPostalCode,Email,MobilePhone,
                                          QAM_DSP__r.Name,QAM_DSP__r.CRD__C,QCC_DSP__r.CRD__C,QAM_DSP__r.FirstName,
                                           QAM_DSP__r.LastName,QCC_DSP__r.FirstName,QCC_DSP__r.LastName,Birthdate,Rep_Status__c,
                                           QCC_DSP__c,Term_Date__c,Start_Date__c,LastModifiedDate,HomePhone,Phone,OtherPhone
                                            from Contact where (Rep_Status__c='Terminated'OR Rep_Status__c='Converted') Limit 1])
         {
              system.debug('TerminateQuery@@@@'+TerminateCntQuery);
               if(TerminateCntQuery.Rep_Status__c=='Converted')
               {         
             TerminateCntList.add(TerminateCntQuery);
             TerminateCntId.add(TerminateCntQuery.id);
             List<License__c> lstLicensesValues=new List<License__c>();
             License__c LicensesValues=[Select Id,License__c from License__c where contact__c  IN:TerminateCntId Limit 1] ;
             lstLicensesValues=[Select Id,License__c from License__c where contact__c  IN:TerminateCntId];
             integer LicensesValue;
             LicensesValue=lstLicensesValues.size();

Please help me

I Tried to pass the list of ids,but its give error while calling method in trigger.

Thanks.

Regards,
Jyo
 
Best Answer chosen by Jyosi jyosi
Chidambar ReddyChidambar Reddy
Hi Jyosi,
 
trigger Rephistorytracking on contact (after update,before update) {  
    RepTriggerHandlerclass contactHandler = new RepTriggerHandlerclass ();
    Jcoreutil    JcoreHandler= new Jcoreutil();
/*
I am not sure what you are doing with contactHandler class, but it is better to make callout in after update context
*/    

if(Trigger.isAfter && Trigger.isUpdate) {
        contactHandler.onAfterUpdate(Trigger.New, Trigger.oldMap);
    }
    
    if(Trigger.IsAfter && Trigger.isUpdate)
    {
        contactHandler.onAftercontactUpdate(Trigger.New);
    }
     if(Trigger.IsUpdate && Trigger.isBefore)
    {
         Jcoreutil.JcoreAdd();
    }

/* try the following */

if(Trigger.isUpdate && Trigger.isAfter){
       ClassName.FutureMethodNameToMakeCallout(trigger.newMap.keyset());

}
 
}

Use the formal parameter of the callout method as Set<Id> like below
 
public class Jcoreutil {
     @future(callout=true)
     public static void JcoreAdd( Set<Id> contactIdSet)
      { 
       /* do your logic by querying from contactIdSet */
       // Remember that you are allowed to make 10 callouts per transaction
      }
}


Thank you
Choose it as best answer if it has helped you
 

All Answers

kiranmutturukiranmutturu
Do you mean when you are adding a parameter to the method like JcoreAdd(ids) is giving an error right?

Method structure  ---- JcoreAdd(List<Id> ids) 
Chidambar ReddyChidambar Reddy
Hi Jyosi,
 
trigger Rephistorytracking on contact (after update,before update) {  
    RepTriggerHandlerclass contactHandler = new RepTriggerHandlerclass ();
    Jcoreutil    JcoreHandler= new Jcoreutil();
/*
I am not sure what you are doing with contactHandler class, but it is better to make callout in after update context
*/    

if(Trigger.isAfter && Trigger.isUpdate) {
        contactHandler.onAfterUpdate(Trigger.New, Trigger.oldMap);
    }
    
    if(Trigger.IsAfter && Trigger.isUpdate)
    {
        contactHandler.onAftercontactUpdate(Trigger.New);
    }
     if(Trigger.IsUpdate && Trigger.isBefore)
    {
         Jcoreutil.JcoreAdd();
    }

/* try the following */

if(Trigger.isUpdate && Trigger.isAfter){
       ClassName.FutureMethodNameToMakeCallout(trigger.newMap.keyset());

}
 
}

Use the formal parameter of the callout method as Set<Id> like below
 
public class Jcoreutil {
     @future(callout=true)
     public static void JcoreAdd( Set<Id> contactIdSet)
      { 
       /* do your logic by querying from contactIdSet */
       // Remember that you are allowed to make 10 callouts per transaction
      }
}


Thank you
Choose it as best answer if it has helped you
 
This was selected as the best answer
Jyosi jyosiJyosi jyosi
Thanks a Lot Chidambar Reddy