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

Downloading a file in crt or cert format

hi , i wolud like to download a file in crt format that is a certificate format ,so could  any one pleas let me know the solution in apex


Where do you store this file?in documents,in content?



the extension of the file has to be as crt or cert , an once i click on download the file has to be download to my local machine wiht that desired format, could u let me the sample code in visulaforce, ihave tried like this but the file is stored in text format



<apex :page contentType="application/cert" >


It is clear now,You can achieve this by dowloading as attachments.


Here is asome sample codes.


We assume that ur Visualforce name is "CrtPage".

PageREference CertPage=Page.CrtPage;


Attachment att=new Attachment();




insert att;

PageReference DownloadPage=new PageReference('/servlet/servlet.FileDownload?file='+att.Id);


return DownloadPage;



i have try with ur code, but i have ended up with an error while i click on download


System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Parent]: [Parent]


could u help me with a solution


Thats my missing,you have to set Parent Id in attachments object.

I can explain the parent Id like this:


Parent Id links the whose attachment this is.


For example. My account.nAme: Test

Account.Id: 'ab5949aasldlad8';




Please use document with same logic.You dont need to set a field like a parent Id for document object.


Hello sir,

 thanks for your valuable response, but i am not using AccountId as u specified above, i would like you u gide me, as  i am new to apex.Actually i need to downlaod a page which contains a string and when i click on downlaod the string has to be saved to that file with an extension as crt, this is what i am lookinf for.So, if u could please guide me how could i achieve this


i would be greatful if oblized