2

HI friends for setWhatId i am unable to assign custom object record id. I am getting following exception. caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, Only contracts, cases, products and opportunities allowed for whatIds.: []

That means we can not use custom object records as merge fields ?. Its really bad from salesforce.

whatId when using custom object

1

1 Answer 1

2

If you're sending the mass email to a list of contacts, what you describe is in the Apex documentation under MassEmailMessage Class:

setWhatIds(whatIds)

Optional. If you specify a list of contacts for the targetObjectIds field, you can specify a list of whatIds as well. This helps to further ensure that merge fields in the template contain the correct data.

Signature

public Void setWhatIds(ID[] whatIds)

Parameters

whatIds

Type: ID[]

Return Value

Type: Void

Usage

The values must be one of the following types:

  • Contract
  • Case
  • Opportunity
  • Product
4
  • i must admit, I find this restriction to be inexplicable
    – cropredy
    Commented Dec 31, 2016 at 21:30
  • @cropredy I don't write the documentation, I just regurgitate it. ;)
    – crmprogdev
    Commented Dec 31, 2016 at 22:57
  • looks like its better to use SingleEmailMessage . Here for setWhatId(whatId) i can use custom objects too.The value must be one of the following types: Account Asset Campaign Case Contract Opportunity Order Product Solution Custom
    – mak k
    Commented Jan 3, 2017 at 5:50
  • @makk That would be correct. The only way to do what you want is to use SingleEmailMessaging methods, not MassEmail Methods
    – crmprogdev
    Commented Jan 3, 2017 at 12:54

You must log in to answer this question.

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