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
Poorna DeveloperPoorna Developer 

Future method cannot call from future method or batch class

Helo Everyone,
  I have written an apex code to get order object data from process builder by using invocable method.
And also I had performed some task like create json data and pass that json data in to webservice to get server resposnse.

Here my code,
public with sharing class OrderActivation
     @InvocableMethod(label='getorderid' description='Get order record id from order')
    public static void getdata(getcustomerid[] requests)
        String recordId,bCity,bStreet,bState,bZip,bCountry,sCity,sStreet,sState,sZip,sCountry,orderAmount,cCity,cStreet,cState,cZip,cCountry,cName,cEmail;
         string jsonString;
        for(getcustomerid request : requests)
             recordId=  request.recId;
            System.debug('order Id:::::  '+recordId);            
          RootObject objJSONRoot = new RootObject();  
        Merchant merch = new Merchant();
        merch.signature = '73242ibc7osfsdfb5|tuJEH3gNbeWJsdfsdffIHah||nbobljsdhgfjsdhjbnmdli0poys|doU3HJVosdfsfwefym7MQ44qf7cpn7pc';
        merch.tariff = 10423004;
        Customer cus = new Customer();
        cus.country_code=request.cCountry;; = request.cEmail;
        cus.customer_ip = '';
        cus.customer_no = '9265'; ='+49 089 123456'; = '+49 174 7781423';
        Transactions tran = new Transactions();
            tran.payment_type ='INVOICE';
        tran.amount = '100';
        tran.currencyX= 'EUR';
        tran.order_no = '12';  
        Custom cu = new Custom();
        objJSONRoot.merchant = merch;
        objJSONRoot.customer = cus;
        objJSONRoot.transactions = tran;
        objJSONRoot.cust = cu;
        jsonString = JSON.Serialize(objJSONRoot);
        System.debug('jsonString::: ' +jsonString);   
    public static void OrderGet(string recordId, string jsonString)
          String BodyData = jsonString;
             String OrderId = recordId;
                    System.debug('Json Body::::'+BodyData);
            Order od = new Order(id=OrderId);
             String endpointurl = 'https://sample.webserver';
               Http http = new Http();
            HttpRequest req = new HttpRequest();
            req.setHeader('Content-Type', 'application/json');
            HttpResponse responseg = http.send(req);
            String response = responseg.getBody();
          od.Transaction_Data__c = response;
            update od;  
             catch(Exception e){
            System.debug(LoggingLevel.ERROR, e.getMessage());   
    public static string generateJSON(String jsonString, String request)
        String first_name = 'Max';
        String last_name ='cName';
       //string email ='test@com';
        string customer_ip = '';
        string customer_no = '9265';
        string tel ='+49 089 123456';
        string mobile = '+49 174 7781423';
        string payment_type = 'INVOICE';
        string amount = '1000';
        string currencyX = 'EUR';
        string test_mode = '1';
        string due_date = '2021-08-05';
        string invoice_ref = 'BNR-14-8410121284';
        string order_no = '84112121084';
        string lang ='EN';
        String city = 'San Francisco';
        String sState = 'CA';
        String zip = '946556105';
        String country_code = 'US';
        RootObject objJSONRoot = new RootObject();
       String jsonData = JSON.Serialize(objJSONRoot);
       // jsonData = jsonData.replace('"currency":', '"currencyX":');
      //  System.debug(jsonData);
        return jsonData;
   public class RootObject
        public Merchant merchant { get; set;}
        public Customer customer { get; set;}
        public Transactions  transactions {get;set;}
        public Custom cust {get;set;}
    public class Merchant
        public string signature { get; set; }
        public integer tariff { get; set; }
    public class Customer
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string email {get;set;}
        public string house_no {get;set;}
        public string street {get;set;}
        public string city {get;set;}
        public string zip {get;set;}
        public string sState {get;set;}
        public string country_code {get;set;}
        public string customer_ip{get;set;}
        public string customer_no{get;set;}
        public string tel{get;set;}
        public string mobile{get;set;}
    public class Transactions
        public string payment_type {get;set;}
        public string amount {get;set;}
        public string currencyX {get;set;}
        public string test_mode {get;set;}
        public string due_date {get;set;}
        public string invoice_ref {get;set;}
        public string order_no {get;set;}
    public class Custom
        public string lang {get;set;}
    public class getcustomerid
         //request billing address related invocable variables and make variables as required one  
            public String recId;//Get Order record id
            public String bStreet;
            public String bState;
            public String bCity;
            public String bZip;
            public String bCountry;
        //request shipping address related invocable varibales and makes variables a required one
            public String sStreet;
            public String sState;
            public String sCity;
            public String sZip;
            public String sCountry;
         //request order amount related invocable varibales and makes variables a required one
            public String orderAmount;
       // cCity,cStreet,cState,cZip,cCountry,cName;
            public String cCity;
            public String cStreet;
            public String cState;
            public String cZip;
            public String cCountry;
            public String cName;
            public String cEmail;

I'm getting error like Future methode cannot call from future method or batch class.

Any help!!
Thanks in advance.
Abdul KhatriAbdul Khatri
Hi Poorna,

Do you have a trigger on SObject Order that may be triggering this same code when you made update on the order under Future call.

User-added image

Abdul KhatriAbdul Khatri

Hi Poorna
Your problem fixed?