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
Ravi_SFDCRavi_SFDC 

Generate a PDF and attach PDF to a Object

I do have 10 accounts and for each account i do have a account plan with lot of categories. Requirement is as below. At end of every month, a batch job needs to generate a PDF version of the account plan for each account and upload it to the account review object as it’s attachment. Can anyone help with this regard

Thanks
Venkata
JeffreyStevensJeffreyStevens
Code the VF page and do the renderAs="pdf".

Then in the APEX do
pageReference pdfPage = Page.VFPageName;
blob pdfBody;
pdfBody = pdfPage.getContentAsPDF();

Then Insert an Attachment record, setting the Body field = to the pdfBody field. And set the ParentId field = the Account ID.
 
Aniket Malvankar 10Aniket Malvankar 10
Hello Venkata,

You can just create an Attachment on the Account. It should work the same way as creating an object in Salesforce.
Some important considerations:
The API sends and receives the binary file attachment data encoded as a base64Binary data type. Prior to creating a record, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary (this conversion is usually handled for you by the SOAP client).
The create call restricts these files to a maximum size of 5 MB. For a file attached to a Solution, the limit is 1.5MB. The maximum email attachment size is 3 MB.


Regards
Aniket
Ravi_SFDCRavi_SFDC

Thank you Jeffrey and Aniket.

Aniket: My requirement is as this I do have 10 accounts and for each account i do have a account plan with lot of categories (Account Priorities, Top Risks etc). At end of every month, a batch job needs to generate a PDF version of the account plan for each account and upload it to the account review object as it’s attachment.

How would i convert only the account plans of all the account into a pdf with versioning and upload them to the account review object as attachment for reference. Please suggest. Sample code will me.