Possible Duplicate:
sendemail method not working

  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 ];
         for(Designer_Content_Data__c econtent:emailcontentinfo)


       email1.setToAddresses(new string[] {useremail});

      Messaging.sendEmailResult[] res = Messaging.sendEmail(new Messaging.singleEmailMessage[]{email1});
        for(Messaging.sendEmailResult result:res)

               }catch(EmailException e){
     //Messaging.sendEmail(new Messaging.singleEmailMessage[] {email1});


      public void Save()
 Designer_Content_Data__c emailcontentinfo = [select Mail_Content_Data__c from Designer_Content_Data__c where Designer__r.name =:Template limit 1 ];
            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

  • did you try the same in some other method instead of save?
    – Sathya
    Nov 5, 2012 at 12:05
  • I just created a command button for sendemail method and it worked well.....Apart from it I didn't tried in any other method
    – Eagerin Sf
    Nov 5, 2012 at 12:08
  • no i mean to say that save is a standardcontroller method.. not sure if you are using standcontroller or custom controller here. thats why am saying please check with a different method name
    – Sathya
    Nov 5, 2012 at 12:10
  • same error...System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
    – Eagerin Sf
    Nov 5, 2012 at 12:14
  • 1
    I'd like to suggest that you take a moment and give some context to what you're trying to do, why you're doing it this way, etc. Just posting a block of code with the exception you're receiving doesn't make for a great question. Please explain some more.
    – pchittum
    Nov 5, 2012 at 14:45

1 Answer 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.

  • getting null values
    – Eagerin Sf
    Nov 5, 2012 at 12:26
  • I have edited my save method now getting all the values correctly in debug logs correcrtly but still getting the same error....System.CalloutException :(
    – Eagerin Sf
    Nov 5, 2012 at 13:51

Not the answer you're looking for? Browse other questions tagged .