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
SewaltherSewalther 

@InvocableMethod Class not making call to Endpoint

I have a process that invokes an @InvocableMethod Class, which should post to an endpoint. I am not getting any errors, but it isn't making the call. My Class is below. What am I missing? Any help is appreciated. Thank you!


global class SalesCloudOnboardCustomerClass {
  
    @InvocableMethod(label ='Call Sales Cloud' description='Sends the Opportunity Id to Sales Cloud.')
    public static void makeCallout(List<Id> ids) {
      System.debug('DebugMe ids: ' + ids);
      String endpoint='';
      HttpRequest request = new HttpRequest();
      // Set the HTTP verb to POST.
      request.setMethod('POST');

      for(Id id : ids){
        //Set the endpoint URL.
        Remote_Endpoint__mdt onboardCustomer = [select Endpoint__c from Remote_Endpoint__mdt where QualifiedApiName = 'OnboardCustomer' Limit 1];
          endpoint = onboardCustomer.endpoint__c + id;
        }
                
     
        // Set the endpoint URL.
        request.setEndPoint(endpoint);
        // Set timeout to 40 seconds.
        request.setTimeout(40000); 
        // Send the HTTP request and get the response.
        System.debug('DebugMe request: ' + request);
        //HttpResponse response = new HTTP().send(request);
        
      }

  }
Best Answer chosen by Sewalther
Waqar Hussain SFWaqar Hussain SF
Add your webservice call in a future method and then call that future method from your @invocableMethod.
 
@future(callout=true)


https://salesforce.stackexchange.com/questions/120012/problem-with-process-builder-invocable-method-and-webservice-call-out

All Answers

MandyKoolMandyKool
Is your process builder activiated?
Is it printing debug statements?
SewaltherSewalther
It is and when I look at the debug logs, I think it will make the call, and then it doesn't...

16:03:54.558 (564622195)|USER_DEBUG|[23]|DEBUG|DebugMe request: System.HttpRequest[Endpoint=https://salescloudxxxxxxxxx.com/onboard/new/0070S000002iTvaQAA, Method=POST]

Debug Log ends with this:
​16:03:54.558 (564699649)|CODE_UNIT_FINISHED|SalesCloudOnboardCustomerClass.makeCallout 16:03:54.552 (564964629)|FLOW_START_INTERVIEWS_END|1 16:03:54.492 (565484567)|WF_FLOW_ACTION_END|06L0S0000002KZv 16:03:54.492 (565649955)|WF_TIME_TRIGGERS_BEGIN 16:03:54.492 (582697551)|WF_ACTIONS_END| Flow Trigger: 5;
Waqar Hussain SFWaqar Hussain SF
Add your webservice call in a future method and then call that future method from your @invocableMethod.
 
@future(callout=true)


https://salesforce.stackexchange.com/questions/120012/problem-with-process-builder-invocable-method-and-webservice-call-out
This was selected as the best answer
SewaltherSewalther
Thanks, Waqar. Definitely is the solution. Unfortunately, I am not experienced enough to figure out how to call the @futuremethod from within the body of the @Invocablemethod and keep getting errors...
Waqar Hussain SFWaqar Hussain SF
Hi Sewalther,

See below apex code where I have implemented your provided apex callout in a future method. 
global class SalesCloudOnboardCustomerClass {
  
    @InvocableMethod(label ='Call Sales Cloud' description='Sends the Opportunity Id to Sales Cloud.')
    public static void makeCallout(List<Id> ids) {
      System.debug('DebugMe ids: ' + ids);
      callWebService(ids);
        
    }
	  
	@future(callout=true)
	public static void callWebService(List<Id> ids){
	  // Your callout logic
	  String endpoint='';
      HttpRequest request = new HttpRequest();
      // Set the HTTP verb to POST.
      request.setMethod('POST');

      for(Id id : ids){
        //Set the endpoint URL.
        Remote_Endpoint__mdt onboardCustomer = [select Endpoint__c from Remote_Endpoint__mdt where QualifiedApiName = 'OnboardCustomer' Limit 1];
          endpoint = onboardCustomer.endpoint__c + id;
        }
                
     
        // Set the endpoint URL.
        request.setEndPoint(endpoint);
        // Set timeout to 40 seconds.
        request.setTimeout(40000); 
        // Send the HTTP request and get the response.
        System.debug('DebugMe request: ' + request);
        HttpResponse response = new HTTP().send(request);
		system.debug('response::'+response.getBody());
	}

  }

 
SewaltherSewalther
THANK YOU!!!!!