0

enter image description hereAn apex method that returns a continuation object can’t perform DML. The solution given by the Salesforce developer documentation is the “perform DML operations in the Apex callback method”. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_continuations_limits.htm

I tried to do DML operations in the Apex callback method in new Continuation approach. But it was not working. Continuation was failed. It gave below error. What should I do for this? Debug log of the error

public with sharing class newContinuation1 {
    private static final String LONG_RUNNING_SERVICE_URL =
        'http://dummy.restapiexample.com/api/v1/employees';
    public static List<String> requestLabel;
    public static String result; 

    @AuraEnabled(continuation=true cacheable=false)
    public static Object getstartRequest() {
        Continuation con = new Continuation(40);
        con.continuationMethod='processResponse';
        con.state='SUCCESS';
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setEndpoint(LONG_RUNNING_SERVICE_URL);
        con.addHttpRequest(req);        
        return con;
    }

    @AuraEnabled(cacheable=false)
    public static Object processResponse(List<String> labels, Object state) {

        HttpResponse response = Continuation.getResponse(labels[0]);

        String result = response.getBody();
        Account acct1 = new Account(Name='samushika333');
        try
        {
            insert acct1;
            return result;
        } catch (DmlException e) {
            System.debug('Exception'+e);
            return result;
        }

    }

}
  • Is your aura method have `cacheable=true? – Pranay Jaiswal Jul 2 at 10:19
  • I did DML operation with and without @AuraEnabled (Cacheable=true) annotation. but it failed in both cases. – R_Chamini Jul 2 at 13:01
  • Is it Aura or LWC? Cause in aura if you set setCacheable as true we get same exception – Pranay Jaiswal Jul 2 at 13:31
  • Yes. I added both screenshot and the code to the original post. – R_Chamini Jul 2 at 13:43
  • This is Aura. can't we do DML operation within the callback method? – R_Chamini Jul 2 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.