-1

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

5
  • 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

3

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.

2
  • 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 .