function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sourav HazraSourav Hazra 

MIME attachment - how to retrieve using apex

We are working on web service integraiton with salesforce where a document is getting transfered as a MIME attachment in the service. Is there any sample code available how to extract MIME attachment and display as document from salesforce? 
NagaNaga (Salesforce Developers) 
Hi Sourav,

You need to set the MIME Content-Type of the email attachment using the setContentType method.  A registry of the top-level MIME Content-Types and their associated sub-types can be found at http://www.iana.org/assignments/media-types/media-types.xhtml, and one solution would be to get the extension, and then manually put the correct MIME Type (i.e. if ContentVersion.Filetype returns 'pdf', setContentType would need to recieve 'application/pdf')

Instead of having a bunch of conditionals, it would also be possible to work this out through custom settings. Apache keeps a mime.types file that has a list of extensions with their associated MIME type here: http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types. You could make a custom setting for the extensions and their related MIME Type, and then query the custom setting to retrieve the extensions MIME Type.

Please let me know if this helps

Best Regards
Naga kiran
Sourav HazraSourav Hazra
The documment is getting transferred from a DMS to salesforce and requirement is to display the document (could be large in size) from salesforce. Do you think the above approach will work for that?
NagaNaga (Salesforce Developers) 
Hi Sourav,

I think it should work unless the attachment is too big.

Best regards
Naga kiran