I have an email template which I need to build using many information , so I have used apex component

<c:EmailTemplateComp ObjectID="{!relatedTo.Id}" show_url="false"></c:ATEmailTemplate_FirstName> 

and in the controller Im making a web service call out.

When I send the Email using Messaging.sendEmail it throws the error

Programmer Error: transaction committed or rolled back while performing api operation: SendEmail

but if the remove the web service call out the email is sent successfully. Question : Is it not allowed to do a web service call out in apex component controller?

1 Answer 1


You can't perform a callout after DML, which Messaging.sendEmail performs. As a workaround, use Messaging.renderStoredEmailTemplate to first render the text (which can include the callout), and then perform sendEmail using the resulting output. You can perform a callout while sending an email, but the callout must be done first to avoid this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.