Possible Duplicate:
sendemail method not working
@future(callout=true)
public static void sendEmail(string emailcontentbody,string useremail,string Template,string subject){
integer statuscode;
Messaging.singleEmailMessage email1 = new Messaging.singleEmailMessage();
list<Designer_Content_Data__c> emailcontentinfo = [select Mail_Content_Data__c from Designer_Content_Data__c where Designer__r.name =:Template ];
system.debug('emaillidd'+Designer__c.name);
for(Designer_Content_Data__c econtent:emailcontentinfo)
{
emailcontentbody+=econtent.Mail_Content_Data__c;
}
system.debug('emaillll'+emailcontentbody);
email1.setSenderDisplayName('CompanyName');
email1.setHtmlBody(emailcontentbody);
email1.setSubject(Subject);
email1.setToAddresses(new string[] {useremail});
try{
Messaging.sendEmailResult[] res = Messaging.sendEmail(new Messaging.singleEmailMessage[]{email1});
system.debug('resulttt'+res);
for(Messaging.sendEmailResult result:res)
{
if(result.isSuccess()==true)
{
statuscode=0;
}else{
statuscode=1;
}
}
}catch(EmailException e){
statuscode=1;
}
//Messaging.sendEmail(new Messaging.singleEmailMessage[] {email1});
}
public void Save()
{
if(xmlPaymentMethod.Paymenttype=='Invoice'){
Designer_Content_Data__c emailcontentinfo = [select Mail_Content_Data__c from Designer_Content_Data__c where Designer__r.name =:Template limit 1 ];
sendEmail(emailcontentinfo.Mail_Content_Data__c,template,billing.billingemail,'response');
system.debug('sendemailllllll'+emailcontentinfo.Mail_Content_Data__c +template +billing.billingemail);
}
}
Getting all values in save method and getting exception as System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Attribution to: Eagerin Sf
Possible Suggestion/Solution #1
sendEmail is declared as a void return method - i.e. returns nothing.
Morever its a @future call, so it isnt in the same execution context, you can't expect a return value from a future method anyways, as it starts a new thread of execution.
If you wish to check what its doing, I'd suggest setting up Debug Logs (Setup > Monitoring > Debug Logs) and trace the flow there.
Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4056