0

For the SFDC Integration I send out a call to an external application and receive a Success status in my debug log(I am logged in as myself). External application says they are getting multiple pings of “success” over and over for several minutes(5mins+).

FYI: SFDC sends SFDC Id to External Application and the External Application connects to SFDC using Integration user credentials and the WSDL to extract data.

To stop the multiple pings, I freeze the Integration user. In my apex code I have a try catch for when I send my http request, and have set a request timeout(120000) in case there is a timeout. When I go to Setup->Apex Jobs. I can see that the Integration user has a status of processing over and over. I have also noticed in my Debug log there are times when I see two separate callouts sending the same data to the same endpoint.

public class ProcessHandlerShowAccounts 
{
    public static boolean isAlreadyRun=false;
    public class AccountParameter
    {
        @InvocableVariable(required=true)
        public Id accountId;
        @InvocableVariable(required=true)
        public String name;
    }

    @InvocableMethod
    public static void handleNewAccounts(AccountParameter [] accountParameters) 
    {
         if(isAlreadyRun)
        return;
webServiceCallOut(accountParameters[0].accountId,accountParameters[0].name);
          isAlreadyRun=true;
   }  
    @future(callout=true)
    public static void webServiceCallOut(ID n, String a){

        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setTimeout(120000);
        HttpResponse res = new HttpResponse();
        req.setEndpoint('https://something/Accounts'+'?sfdcid='+n+'&operation='+a);

        String username = 'hello';
        String password ='123';
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);

        req.setHeader('Authorization', authorizationHeader);
        req.setMethod('POST');
        //Create a new Http object to send the request object
        //a response object is generated as a result

        try{
              res = http.send(req);

        }catch(System.CalloutException e){
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }  
    }
}

enter image description here

Here is the criteria in the process builder: Account: AND (OR(ISCHANGED( [Account].Name ),ISCHANGED([Account].BillingCity ), ISCHANGED([Account].BillingState ),ISCHANGED([Account].BillingStreet ) ,ISCHANGED( [Account].BillingCountry ),ISCHANGED([Account].BillingPostalCode ) ,ISCHANGED([Account].Site_Use_Code__c ),ISCHANGED([Account].Shipping_County__c ) ,ISCHANGED([Account].Phone),ISCHANGED([Account].Type ) ,ISCHANGED([Account].Industry ),ISCHANGED([Account].DUNS_Number__c ) ,ISCHANGED([Account].Taxpayer_Identification_Number__c ),ISCHANGED([Account].ES_Company_Code__c ),ISCHANGED([Account].Customer_Class__c ),ISCHANGED([Account].HQ_Internal_Customer__c ) ) , NOT(ISNULL([Account].Oracle_ERP_Account__c )), INCLUDES([Account].Business__c , 'something') )

Contact: AND (OR(ISCHANGED([Contact].FirstName ), ISNEW(), ISCHANGED([Contact].LastName), ISCHANGED([Contact].Department ),ISCHANGED([Contact].LastModifiedDate ) ,ISCHANGED([Contact].Title ),ISCHANGED([Contact].Phone ),ISCHANGED([Contact].Email ),ISCHANGED([Contact].OwnerId ) ) , NOT(ISNULL([Contact].Account.Oracle_ERP_Account__c )), INCLUDES([Contact].Account.Business__c, 'something') )

enter image description here enter image description here

1 Answer 1

2

It doesn't look like you have issues with your Apex code. Its more like process builder is getting called again via field update and its again triggering .

Whenever you are calling your invocable method can you add this check in your process builder block. This will make sure you don't call the same block again and again.

enter image description here

If you want to fix it using the code, you have to use a static variable to store the state. Then check the state before making a callout.

public class ProcessHandlerShowAccounts {
    public static boolean isAlreadyRun=false;
     @InvocableMethod
    public static void handleNewAccounts(AccountParameter [] accountParameters) 
    {
        if(isAlreadyRun)
        return;

        webServiceCallOut(accountParameters[0].accountId,accountParameters[0].name);
        isAlreadyRun = true;
    }  
}
13
  • What the pros of using the apex code vs the checkbox in the process builder?
    – nameishi
    Commented Jun 19, 2018 at 13:15
  • 2
    Someone can add another process builder that can call same invocable method, so you have to make sure each process builder is proper. Having it in code will make sure no whatever process builder, wf etc is written your method will only get executed once. Commented Jun 19, 2018 at 13:16
  • Thank you, but What will happen when you return before the webServiceCallout?
    – nameishi
    Commented Jun 19, 2018 at 13:25
  • It won't do a callout... Commented Jun 19, 2018 at 13:25
  • Yeah it did not work, I updated my code and added a image to reflect what is going on in apex jobs
    – nameishi
    Commented Jun 19, 2018 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .