You need to sign in to do that
Don't have an account?

Save a custom object record as a PDF Document and attach to the same record
Hi Guys,
I am trying to develop a trigger(not sure if it is possible through Apex Triggers) to save a custom object record as a pdf document and then attach the same document to that record. we have a custom object called Research, what we want to achieve is when a certain date field is entered and saved then the data in that research record must be saved as a PDF document and get attached to the same record.
I am not sure if this is achievable through triggers only. can anyone give any suggestions for how this can be achieved?
Thanks,
I am trying to develop a trigger(not sure if it is possible through Apex Triggers) to save a custom object record as a pdf document and then attach the same document to that record. we have a custom object called Research, what we want to achieve is when a certain date field is entered and saved then the data in that research record must be saved as a PDF document and get attached to the same record.
I am not sure if this is achievable through triggers only. can anyone give any suggestions for how this can be achieved?
Thanks,
Check this out. Seems like this would work for you. What you are trying to achieve is possible using triggers.
http://corycowgill.blogspot.com/2012/02/generating-pdf-in-apex-trigger.html
Good luck!
Thanks for your quick reply. I will try this out and let you know if I still have any issues.
Thanks,
I tried this solution. Its working very well. but this is grabbing all the fields on to the PDF File. Is there any way to just grab a few fields? I am new to coding can you please help me? The above part of the class grabs all the fields from the record. Any way restrict just the required fields?
also can you please help me in writing test class for this class?
Thanks,
I was able to add only a few required fields to the PDF File by using a if statement. I am now looking to change the order of the fields on the PDF File and display 'Yes/No' instead of 'True/False' on the PDF File. I have opened another discussion for this requirement and I also shared my modified code. Can you please look into it suggest how can this be achieved?
Thanks,
Bathy.
I did not find your new discussion. You can change the fields that you want to display and the order. Using the If statements is a bit limiting, since you are hardcoding the variables that you want to show. There are 2 routes to follow:
- The wrong way, but the easy one. If you are certain that you will not be changing the order of the fields in the future, or removing fields from the "Administration_and_Compliance__c" object in the future, do this:
2. The slightly harder way, but correct.- Create a Custom Setting. Make it a List custom setting. Give it a name of "Account Admin and Compliance Settings". Add a text area field with 255 characters and name it "Fields to include". Create another text area field with 255 characters and name it "Fields to include 2". Then click manage and set a value for both. Add all the fields you want to display on the PDF in the order that you want them to display, separated by commas.
- Use this code:
Please note that contrary to the original code. I have not tested any of these solutions, so there might be compiling errors that you must iron out.
Hope this helps! Good Luck!
Luis
This solution really worked for me.Thanks a lot.But I have one concern.Can we format the pdf such that it displays sections and fields as we have in page layouts.
Any help is appreciated.
Savina
this class helps for a sinle insert or update.
how to do it for List of records.