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
deepakMdeepakM 

You have uncommitted work pending. Please commit or rollback before calling out?

I have class given below

 

 when i call this class method in button ,click i got the follwoing error

 

 

{faultcode:'soapenv:Client', faultstring:'System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, You have uncommitted work pending. Please commit or rollback before calling out: []

Class.ItineraryEmail.SendEmail: line 79, column 1', }

 

the class method is 

 

public string getIB() {

System.debug('Test Flight Request'+listFR);
System.debug('Opportunity'+listOpp);
if(listFR != null && !listFR.isEmpty())
{
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://testwebsite/GetCustomerView?opportunityId='+listFR[0].Opportunity__c+'&flightRequestID='+listFR[0].Id);
req.setMethod('GET');
HttpResponse res = h.send(req);
result = res.getBody();

}
else
{
if(listOpp!=null && !listOpp.isEmpty())
{
result = listOpp[0].Confirmation_Email_Content__c;
}
}
return result;
}

 

please let me know what can i do..

 

thanks in advace

Best Answer chosen by Admin (Salesforce Developers) 
Mayank_JoshiMayank_Joshi

The comman reason for this error is "you cannot do an insert and then do a callout in the same class" .

All Answers

Mayank_JoshiMayank_Joshi

The comman reason for this error is "you cannot do an insert and then do a callout in the same class" .

This was selected as the best answer
deepakMdeepakM

Mayank 

 

i know but i m nott insert anything and then do callout that you can see in my code

 


deepakMdeepakM

Hi 

 

i am not getting any proper solution as i created a class with @future method and call this method in main class ..but in button click i got the error

"@future annotion not allowed this time".

 

thanks