You need to sign in to do that
Don't have an account?
geeta
SingleEmailMessage setDocumentAttachments method
Hi,
As per the Apex documentation, I am trying to use the setDocumentAttachments method in the SingleEmailMessage class. But, I am getting a compilation error "Method does not exist or incorrect signature". Here is the code:
Attachment[] attachment = [Select Id from Attachment where ParentId =:solId];
if(attachment.size() > 0) {
ID[] attchmentId = new ID[attachment.size()];
//attchmentId.size() = attachment.size();
for(Integer g=0; g<attachment.size(); g++)
attchmentId[g] = attachment[g].Id;
mail.setDocumentAttachments(attchmentId);
}
ID[] attchmentId = new ID[attachment.size()];
//attchmentId.size() = attachment.size();
for(Integer g=0; g<attachment.size(); g++)
attchmentId[g] = attachment[g].Id;
mail.setDocumentAttachments(attchmentId);
}
Can anyone please help?
is it 9.0 10.0 or 11.0 ?
are you using Eclipse or the web UI to edit and save your code?
is mail an object in your class ? what type of object is it?
i don't see here where you have created the mail object.
We are using 11.0. Yes, we are using Eclipse to edit and save the code. mail is a SingleEmailMessage object. Messaging.
SingleEmailMessage mail = new Messaging.SingleEmailMessage();
We were able to compile this by changing the ID[] to String[]. However, when we run the code, it fails. Can you please help?
Hi,
As per Apex documentation setDocumentAttachments() Method requires the Id of the Document entity and not Attachment entity.
From your post, its looks like you are passing Attachments Id instead of Document Id. If you use proper exception handling then it will give you INVALID_CROSS_REFERENCE_KEY exception.
So use document Id instead of Attachments Id. And you would be able to run this successfully.