+ Start a Discussion
GYAN ANDRUSGYAN ANDRUS 

Hi,Can anyone help pls ...very urgent....for this for "u have committed fund" error,when this method called ,i am getting an error: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out*


public static void createInvestmentBooking(String investorId, String bookingOrderId, String loanApplicationId, Decimal investmentAmount,
                                               Decimal certificateRate, Decimal serviceRate, String Authorization)
    {
        System.debug('Inside createInvestmentBooking method.');
        JSONGenerator generator = JSON.createGenerator(true);
        generator.writeStartObject();
        generator.writeStringField('investorId', investorId);
        generator.writeStringField('bookingOrderId', bookingOrderId);
        generator.writeStringField('loanApplication', loanApplicationId);
        generator.writeNumberField('investmentAmount', investmentAmount);
        generator.writeNumberField('certificateRate', certificateRate);
        generator.writeNumberField('serviceRate', serviceRate);
        generator.writeEndObject();
        String jsonString = generator.getAsString();
        System.debug('jsonString = '+jsonString);
        HttpRequest request = new HttpRequest();
        request.setMethod('POST');
        String urlName = URL.getSalesforceBaseUrl().toExternalForm()+'/services/apexrest/peer/v/inves';
        System.debug('Booking URL = '+urlName);
        
        request.setEndpoint(urlName);
        request.setHeader('Authorization', Authorization);
        request.setHeader('Content-Type', 'application/json');
        request.setBody(jsonString);    
        Http http = new Http();
        response = http.send(request);
        System.debug('response.getStatus() in createInvestmentBooking = '+response.getStatus());
        System.debug('Fulfillment service returned in createInvestmentBooking'+ response.getBody());
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Dear gyan,

We can not do  DML operation  and  callouts in the same  execution context.

You can use future method to do callout .

Let me know if it helps you .

Regards
Ashish
ashish.sharma.devsfdc@gmail.com