How to create a attacment from visualforce site? I have created godaddy domain in our salesforce and given certificates for domain. for this domain i have access to view the visuaforce pages.I have created visualforce page as renderas"PDF" and i am calling from visualforce page attachment is created successfully but when i run the page from site its not created the attachment. i have given access the visualforce page andenter code here apex controller and also i have given access to object and fields.see below code.

account acc =[select id,name from account where id='myrecordid'];
pagereference pgref = page.mypdfpage;
blob body;
body= pageref.getContentAsPDF();
Attachment attach = new Attachment();
attach.body = body;
attach.Name = 'myattachpage';
attach.Isprivate = false;
attach.ParentId = acc.Id;
attach.ContentType = 'pdf';
insert attach;
  • is the apex class with sharing or without sharing? – Pranay Jaiswal Feb 1 at 10:47
  • @pranay apex class is without sharing – Goldberg Feb 1 at 11:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.