I have created a custom filed in Orders that is a picklist field. On default is pending.

How can I automatically update this field to send when I use the send an email functionality through the activity history?

  • Did you manage to get this resolved? Feb 20, 2015 at 9:46

1 Answer 1


You will need to write a trigger on the Task object.

Then you can perform your picklist value change if a Task object is created where the WhatId field is an Order object and the Subject field begins with 'Email:'.

trigger TaskTrigger on Task (after insert) {
    List<Order> ordersToUpdate = new List<Order>();

    for(Task t : Trigger.new) {
        if(t.WhatId.getSObjectType() == Order.sObjectType 
            && t.Subject.startsWith('Email:')) {
                ordersToUpdate.add(new Order(Id = t.WhatId, My_Picklist_Field__c = 'New Value'));

    update ordersToUpdate;
  • Hi Alex, I try the trigger but first error is Error Error: Compile Error: unexpected token: '{' at line 6 column 46 I delete the { and then I get an error like Error: Compile Error: expecting a right parentheses, found 'ordersToUpdate.add' at line 7 column 12. I then insert a right parenthesis on the left side of orderToupdate and I get an error like Error Error: Compile Error: unexpected token: update at line 11 column 4 Feb 13, 2015 at 9:39
  • @TommyGeorgiou There was a missing ) on line 6, I've corrected it now. Feb 13, 2015 at 9:45
  • I still get an error while using this trigger : Error: Compile Error: Variable does not exist: orderToUpdate at line 11 column 12 Feb 13, 2015 at 9:56
  • @TommyGeorgiou Updated again, I was missing the s from ordersToUpdate. Feb 13, 2015 at 10:05
  • Now it's saved. I will try to upload this onto production to see if it's working since I don't have the send an email into the sandbox. Will come back to you asap Feb 13, 2015 at 10:33

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.