1

1.Currently working on Apex with the flow to pass the API data.

2.If I use @future(callout=true) in apex it throws an error like below.

Error: The only annotation that can be used with InvocableMethod is Deprecated

Apex

public class checkApi 
{
 
 
 @InvocableMethod(label='test' description='Getting customer info from test' )

    @future(callout=true)

    public static void abacuStagingsapi(List<id> appid)
    {
        Map<Id, Apple__c> app =  new Map<Id, Apple__c>([SELECT id,Name,Contact__r.Email FROM 
        Apple__c WHERE Id IN :appid]);

        for(Id Loanapp :appid){

      String endpointurl ='https://th-apex-http-callout.herokuapp.com/animals';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(endpointurl);// update endpoint url
            
request.setMethod('GET');
request.setHeader('x-fern-token', '8IKxGlvbNQCciEpAYmz1yr1LM');
HttpResponse response = http.send(request);
        System.debug(response.getBody());
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
 system.debug('check'+ response.getStatus()); 
    String result = String.valueof(response.getBody());
            String[] emailList= new String[]{app.get(Loanapp)?.Contact__r.Email};
 
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    String[] toAddressesTest = new List<String>(emailList);
    message.setToAddresses(toAddressesTest);
    message.setSubject('API Data');
    message.setHtmlBody(result);
    Messaging.SendEmail(new Messaging.SingleEmailMessage[] {message});
}
}
} 
}

There is any resolve solution there?

1 Answer 1

2

Check the consideration for using invocable method.

  • The invocable method must be static and public or global, and its class must be an outer class
  • Only one method in a class can have the InvocableMethod annotation.
  • Other annotations can’t be used with the InvocableMethod annotation.

Thus the fix would be to call future method from invocable method

public class CheckAPI {
    
@InvocableMethod(label='test' description='Getting customer info from test' )

    public static void abacuStagingsapi(List<id> appid)
    {
        abacuStagingsapiFuture(appid);
    }
    
     @future(callout=true)
    public static void abacuStagingsapiFuture(List<Id> appId){
        
    }
}

You must log in to answer this question.