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 

System.CalloutException Error - While API Integrated

Hi All,

I have a apex code to connect a third party API,

public with sharing class Saltedgelead 
      @InvocableMethod(label='leadsession' description='Create salt edge lead session')
    public static void leadtest()
    public static void geturl()
        String uri;
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setHeader('Content-Type', 'application/json');
            request.setHeader('App-id', 'q_-XTJ_zMjDdH3PiTTSY1q_SbhxYsdfgsg3SB1P3x_9-fJZh8');
            request.setHeader('Secret', 'iBUhgfhgfh6-5dIfUjT3gfNsGrznM-3WQ9ID8UJhMm-8ZsqLGE');
            request.setBody('{"data": {"customer_id": "2911634823132425819231","provider_code": "fake_oauth_client_xf","consent": {"scopes": ["account_details", "transactions_details"]}}}');
            HttpResponse responseg = http.send(request);  
         if (responseg.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
            responseg.getStatusCode() + ' ' + responseg.getStatus());
              String urli = responseg.getBody();
        else {
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(responseg.getBody());
            uri = (string) results.get('token');
        // return responseg.toString();
         Http httpg = new Http();
        HttpRequest requestg = new HttpRequest();
        requestg.setHeader('Content-Type', 'application/json');
       requestg.setHeader('App-id', 'q_-XTJ_zMjDdH3PiTTSY1q_SbhxY3SdsgB1P3x_9-fJZh8');
     requestg.setHeader('Secret', 'iBUdsfgg6-5dIfUjT3gfNsGrznM-3WQ9ID8UJhMm-8ZsqLGE');
       // requestg.setHeader('X-Fern-Token', uri);
        HttpResponse res = http.send(requestg);

        if (res.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
            res.getStatusCode() + ' ' + res.getStatus());
        } else {
     public static void sendingEmail(String email) {
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{''};
        String[] sendingToBccAdd = new String[]{''};
        String[] sendingTocAdd = new String[]{''};
        semail.setSubject('Single Email message Example');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        //return null;

Now I'm invoke this apex class in process builder to send the apex output data as a single mail to the user.

When my process builder start runs I get an error like - 
"We can't save this record because the “Saltedge API” process failed. Give your Salesforce admin these details. An Apex error occurred: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Error ID: 208143754-77391 (-1742348029"

Is I need to change my code? 
Any idea. 

Thanks all.

ShirishaShirisha (Salesforce Developers) 
Hi Poorna,


Seems like you are trying to update the same record using the callout which is being updated by the process builder at the same time.

You can not perform DML and Web service update on the same record.


You need to perform in separate transcations to avoid the error.

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Shirisha Pathuri