I'm having a requirement where I need to send an email at a particular time or at the end of the day for all the Accounts whose status is changed during the day. Here status is a picklist value. How can I query to get all the accounts whose status is changed

  • I don't think you can get the updated fields with a SOQL query. How are you planning to send the email? – Raul Mar 27 '17 at 7:39
  • By using schedulable class and using massemail messaging. Will this works? – Eagerin Sf Mar 27 '17 at 7:41

Its not possible to compare new and old value of field inside a query.

An option would be to create a Boolean field in the object and using Workflows sets its value based on picklist field's.

In Scheduler, query all the records where the field's value is set and after sending email, reset the field value.

  • how can I set a boolean value here since it is a picklist value and can be changed many times in a day.I need to get all the data when ever it is changed and need to send that in a mail – Eagerin Sf Mar 27 '17 at 8:29
  • "I need to get all the data when ever it is changed and need to send that in a mail" - with your second sentence, looks like you could do that in a workflow? – Raul Mar 27 '17 at 8:58

One way of achieving this requirement is to create a object to record all the instances of pick list values changed in a trigger and then send email to them at end of day by querying for records in that object for that particular day.


  1. create an object which has fields like accountId,previousPicklistvalue, new piclistValue, booleanFlag to tell if email is already sent or not.
  2. After trigger to record whenever interested field is updated and then insert a new row in that object with the accountId and other values.
  3. A schedule job which gives you a list of all accounts,which in turn gets you email id's and then send emails.
  • Let me try this scenario – Eagerin Sf Mar 27 '17 at 9:15
  • @EagerinSf did this approach work? – night crawler Mar 28 '17 at 21:59
  • As of now we are not getting all the changed values in the email.Hence kept a boolean field as Rahul suggested – Eagerin Sf Mar 30 '17 at 10:14

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.