2
Database.query('select (Select Name, BodyLength, ContentType from Attachments), Id,Name from Expense__c where Custom_Object__c =: CustomObjectID')

gives response like <br>
  Attachments(
Attachment:{Name=file2.jpg, BodyLength=658456, ContentType=image/jpeg}, <br>
Attachment:{Name=file1.txt, BodyLength=618, ContentType=text/plain}, <br>
Attachment:{Name=file.cls, BodyLength=117141}, <br>
)
4

Most likely the ContentType is null in the database. Salesforce infers the ContentType for "well known" file extensions such as .jpg and .txt when a file is attached but it looks like it does not have a built in file extension to ContentType mapping for .cls.

Correction: this https://stackoverflow.com/questions/1201945/how-is-mime-type-of-an-uploaded-file-determined-by-browser says it is the browser that works out the MIME type not the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.