You need to sign in to do that
Don't have an account?

Problem in selecting the 'To' recipient dynamically using a trigger.
Hi,
We have a custom object linked to a contact. I have a trigger which has to send out an Email to the associated contact on the status change of the custom object.
But I am unable to configure the trigger to dynamically identify the contact's email address and send the Email.
What can be done? I am quiet new to APEX and hence cant figure this out.
I have tried to use the followign functions, but I'm not getting the expected result.
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses( toAddresses );
String[] toAddresses = new String[] {le.CustomObject__r.Contact__r.Email};
Ady
You have to write a soql to retrive the to address from your custom object.
below is the sample code.
String[] toAddresses = new String[]{[select email fromUserwhere id = :UserInfo.getUserId()].email};