Hey Guys,
Finally i did it.I had to send multiple salesforce contents as attachments with the Email.
I was stucked for 3 days and finally its Done.
tada here is the help.....
///tempList is a list that contains that contains the ContentDocumentIds of the selected Contents
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Contact contact = [select Email from Contact where ID=:test.ContactTo__c];
toaddress.add(contact.email);
mail.setToAddresses(toaddress);
mail.setSubject(subject);
mail.setPlainTextBody(body.replace('&','&'));
mail.setUseSignature(false);
Messaging.EmailFileAttachment[] attach = new Messaging.EmailFileAttachment[tempList.size()];
.substring(contentVersion[i].PathOnClient.indexOf('.')+1
,contentVersion[i].PathOnClient.length());
efa.fileName = contentVersion[i].Title+'.'+str;
efa.setInline(false);
efa.Body=attachBody;
attach[i]=efa;
}
if(tempList.size()>0)
mail.setFileAttachments(attach);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail },false);
Hope it helps.
Enjoy Salesforcing......
Finally i did it.I had to send multiple salesforce contents as attachments with the Email.
I was stucked for 3 days and finally its Done.
tada here is the help.....
///tempList is a list that contains that contains the ContentDocumentIds of the selected Contents
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Contact contact = [select Email from Contact where ID=:test.ContactTo__c];
toaddress.add(contact.email);
mail.setToAddresses(toaddress);
mail.setSubject(subject);
mail.setPlainTextBody(body.replace('&','&'));
mail.setUseSignature(false);
Messaging.EmailFileAttachment[] attach = new Messaging.EmailFileAttachment[tempList.size()];
ContentVersion[] contentVersion = new ContentVersion[tempList.size()];
for(integer i=0;i<tempList.size();i++)
{
Blob attachBody;
for(integer i=0;i<tempList.size();i++)
{
Blob attachBody;
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
String temp1 = tempList[i];
String temp1 = tempList[i];
contentVersion[i] = [Select id,Title,VersionData,PathOnClient from
ContentVersion WHERE ContentDocumentId =: temp1];
attachBody = contentVersion[i].VersionData;
String str = contentVersion[i].PathOnClientContentVersion WHERE ContentDocumentId =: temp1];
attachBody = contentVersion[i].VersionData;
.substring(contentVersion[i].PathOnClient.indexOf('.')+1
,contentVersion[i].PathOnClient.length());
efa.fileName = contentVersion[i].Title+'.'+str;
efa.setInline(false);
efa.Body=attachBody;
attach[i]=efa;
}
if(tempList.size()>0)
mail.setFileAttachments(attach);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail },false);
Hope it helps.
Enjoy Salesforcing......
Hi Swati, this helped me greatly. What did your visualforce page look like? How did you provide a list of content to select from? Thanks - Drew.
ReplyDeleteVery helpful. Have you had trouble with a view state being too large?
ReplyDelete