+ Start a Discussion
Lukas van RooyenLukas van Rooyen 

future method not posting with invocable variable

public with sharing class StackItCalculationInfo 
{
       public class UserInput
       {
        @InvocableVariable(required = true)
        public String ItemId;
        @InvocableVariable(required = true)
        public String ClientId;
        @InvocableVariable(required = true)
        public String QuoteId;

    }
     
    

    @InvocableMethod(label='Calculation Info')
    public static void CalcInfo(List<UserInput> userInputs)
    {
           UserInput userInput = userInputs[0];
           string jsonData = JSON.serialize('{"ItemId":' + userInput.ItemId + ', "ClientId":' + userInput.ClientId + ', "QuoteId":' + userInput.QuoteId +'}');
        doCalloutFromFuture(jsonData);
               
    }
    
    @future(callout=true)
    public static void doCalloutFromFuture(string jsonData){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
           request.setTimeout(25000);
        request.setEndpoint('https://endpoint');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody(jsonData);
        HttpResponse response = http.send(request);
        
        // Parse the JSON response
        if (response.getStatusCode() != 200) 
        {

            System.debug('The status code returned was not expected: ' +
            response.getStatusCode() + ' ' + response.getStatus());
        } 
        else 
        {

            System.debug(response.getBody());
        }
    }


}
Suraj Tripathi 47Suraj Tripathi 47

Hi,

You can take references from the below link.

https://www.biswajeetsamal.com/blog/tag/invocablemethod/

https://salesforce.stackexchange.com/questions/204473/future-method-and-static-variables

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm

Please mark it as the best answer if it helps you

Thank You