I was writing a trigger to send email . after inserting a record i was getting an id of that record in trigger. Using this trigger i want to get email id from external webservice.

trigger sendEmail on Task (after insert) {
         for(Task task: Trigger.new){
   Id id=task.ID;
   GetEmailIDbyBSId gm=new GetEmailIDbyBSId();
  String email=  gm.getEmail(id);


code of GetEmailIDbyBSId calss

  public class GetEmailIDbyBSId {

          public String getEmail(String BluestarId)
          String email;

          // code for invoking external system and getting related email id

          return email;


but here the big problem is 'Callout from triggers are currently not supported.' ,when i uase @future i cannot return email Id. So is there any way to achieve this. And the main thing is i am not supposed to store email id in any object i have to get it through web service call and have to store it in a variable for email processing

  • 1
    What I can suggest, relocate logic to send email to some batch process and do call outs from there . From trigger just write logic to update records for which batch processing needs to be done. In batch process, you can directly get Email as response Commented Jul 3, 2015 at 7:38

1 Answer 1


You will need to move all the processing that is dependent on the response from the callout into the future call. Consider passing the TaskId(s) into the future method to keep the trigger to a minimum.

If you are processing a large number of tasks it may be beneficial to queue up the required emails and then have a batch job process them periodically. This might make managing the callouts easier.

  • sure.. this seems to be good to achieve my task... i will move all email sending part to future method ... thanks
    – Rajasekhar
    Commented Jul 3, 2015 at 7:44

You must log in to answer this question.

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