Hi,
I have following code to create email record. It is working fine if I set any Account as "Send To". But if I try to set any Contact as "Send To", it doesn't work and throws error of "Not Found". Error in response: Account doesn't find record with Id "8b4597d2-34c1-e711-810e-5065f38a9b91"
Here is code:
function sendEmail()
{
//Send To: Contact whose id is "8b4597d2-34c1-e711-810e-5065f38a9b91"
var entityApiName = "contacts";
var recordid= "8b4597d2-34c1-e711-810e-5065f38a9b91";
var loggedInUserId = getUserId();
var webapiPath = serverUrl + "/api/data/v8.0/emails";
var email = {};
email["subject"] = "Map notification: ";
email["description"] = "Thank you.";
var parties = [];
//ActivityParty (From)
var sender = {};
sender["partyid_systemuser@odata.bind"] = "/systemusers(" + loggedInUserId + ")";
sender["participationtypemask"] = 1; //From
//add this to collection
parties.push(sender);
//if I comment following if condition (Send To), email record creates successfully
//ActivityParty (To)
if (entityApiName == "contacts" || entityApiName == "accounts" || entityApiName == "leads") {
var receiver = {};
receiver["partyid_account@odata.bind"] = "/" + entityApiName + "(" + recordid + ")";
receiver["participationtypemask"] = 2; //To
parties.push(receiver);
}
email["email_activity_parties"] = parties;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: webapiPath,
data: JSON.stringify(email),
async: false,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=*");
XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
},
success: function (data, textStatus, XmlHttpRequest) {
alert("Email saved successfully");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest);
}
});
}
If I set entityApiName = "accounts" and set recordid of an account, it creates record successfully. It means I can set any account as "Send To" but I can't set any Contact as "Send To".
Please guide me. I want to set Account/Contact and Lead record as "Send To".
Thank you.







