[SalesForce] Callout from triggers are currently not supported.:how to get token from web service in trigger without storing it in any object

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

Best Answer

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.

Related Topic