You need to sign in to do that
Don't have an account?
TCS CRMOnDemand
SingleEmailMessage -> setDocumentAttachments method throws Compilation Error
When trying to add mulitple attachments to a emailmessage using the setDocumentAttachments method of SingleEmailMessage , Apex code throws compilation error
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Attachment[] attachment = [Select Id from Attachment where ParentId =:solId];
Attachment[] attachment = [Select Id from Attachment where ParentId =:solId];
if(attachment.size() > 0)
{
ID[] attchmentId = new ID[attachment.size()];
for(Integer g=0; g<attachment.size(); g++)
attchmentId[g] = attachment[g].Id;
mail.setDocumentAttachments(attchmentId);
}
{
ID[] attchmentId = new ID[attachment.size()];
for(Integer g=0; g<attachment.size(); g++)
attchmentId[g] = attachment[g].Id;
mail.setDocumentAttachments(attchmentId);
}
Is there something being missed from above code ?
Hi,
Use String[] as a parameter to setDocumentAttachments() method. I think its a bug in the Apex. As per documentation, above method taks array of ID. But It gives compilation error for that. setDocumentAttachments() runs successfully when string array is passed as a parameter.
One important point is: This string array should contain the ID of Document entity and not Attachment entity.
If you pass the Attachment entity Id then it will throw run time exception (INVALID_CROSS_REFERENCE_KEY).
Regards
V. R.