You need to sign in to do that
Don't have an account?
kiran punuru
Unable to find the reason for the error
Hi ,
I am getting below error and unable to find the root cause please advise:
@@@Error Message:SendEmail failed. First exception on row 0; first error: INVALID_CONTENT_TYPE, An invalid value (ContentPost) was specified for contentType.: [fileAttachments, ContentPost]
Thanks
kiran
I am getting below error and unable to find the root cause please advise:
@@@Error Message:SendEmail failed. First exception on row 0; first error: INVALID_CONTENT_TYPE, An invalid value (ContentPost) was specified for contentType.: [fileAttachments, ContentPost]
Thanks
kiran
Have you used setContentType method?
You need to set the MIME Content-Type of the email attachment using the setContentType method.
Thanks,
Sagar
public without sharing class SendEmail {
public static void emailSenderMethod(Set<Id> feedItemIds){
System.debug('@@@feedItemIds:'+feedItemIds);
List<FeedItem> lstFeedItem = [Select id,RelatedRecordId,type,body from FeedItem where Id IN:feedItemIds];
for(Feeditem fd :lstFeedItem){
if(fd.Type == 'ContentPost') {
ContentVersion cv = [Select id,FileType, ContentDocumentId,ContentUrl,VersionData ,Title from ContentVersion Where Id = :fd.RelatedRecordId ];
System.debug('@@@ Feed Body: ' + fd.Body);
System.debug('@@@ Document Id: : ' + cv.ContentDocumentId);
System.debug('@@@ Document Title: : ' + cv.Title);
System.debug('@@@@ Document Type: '+fd.Type);
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType(cv.FileType);
attach.setFileName(cv.Title);
attach.setInline(false);
attach.Body = cv.VersionData;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'abc.xyz@test.com'};
String[] ccAddresses = new String[] {'kirankumar.punuru@test.com'};
mail.setUseSignature(false);
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo('kirankumar.punuru@test.com');
mail.setSenderDisplayName('Kiran Kumar reddy Punuru');
mail.setSubject('The Below File Has been uploaded : ');
mail.setHtmlBody('Here is the email you requested: '+cv.Title);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mail.setBccSender(false);
try{
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
catch(Exception e){
System.debug('@@@Error Message:'+e.getMessage());
}
}
}
}
}
Please determine and provide the correct content type as mentioned in this post - http://salesforce.stackexchange.com/questions/2058/determine-the-correct-file-type-extension-for-an-attachment
I am unable to get the point in that link .If you can understand please tell me
Thanks
Kiran
This will not set the correct content type for your attachment, cv.filetype will return file type ie., pdf, txt, png etc..
Content Type is something like :
In line attach.setContentType(cv.FileType); pass attach.setContentType(cv.contentDocument,FileType); this will work.