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

Sending email with sforce.SingleEmailMessage() - Need to relate the message to a record
Hi All
Ive been playing with the sforce.SingleEmailMessage() ability in SFDC to send an email from a custom object and it works really well with the exception that i cannot see any ability to relate it back to the custom object as an activity.
At the moment the email relates to the contact (amc__Project__c.amc__ContactId__c), which i want it to, but i also want to relate it back to the record where the button is (amc__Project__c.Id).
Within this documentation i cannot see any reference to linking back to an object which i can see when i click the 'Send an email' link and fill it out manually, ive put a screenshot below of the field im talking about.
Any help is appreciated
JS For the button

Ive been playing with the sforce.SingleEmailMessage() ability in SFDC to send an email from a custom object and it works really well with the exception that i cannot see any ability to relate it back to the custom object as an activity.
At the moment the email relates to the contact (amc__Project__c.amc__ContactId__c), which i want it to, but i also want to relate it back to the record where the button is (amc__Project__c.Id).
Within this documentation i cannot see any reference to linking back to an object which i can see when i click the 'Send an email' link and fill it out manually, ive put a screenshot below of the field im talking about.
Any help is appreciated
JS For the button
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} var message = new sforce.SingleEmailMessage(); message.replyTo = "{!User.Email}"; message.targetObjectId = "{!amc__Project__c.amc__ContactId__c}"; message.templateId = "00X5B000000LxrD"; message.saveAsActivity = true; var result = sforce.connection.sendEmail([message]); if (result[0].getBoolean("success")) { alert("Email Sent"); } else { alert( cResult[0].errors.message); }The field in the send an email button
message.setWhatId (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_setWhatId)