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
Michelle PoirierMichelle Poirier 

Trigger code to auto-create PDF when quote status changes to "Presented"

I'm am trying to make a trigger to auto save pdf when quote status changes to presented 

Also, I have 2 templates - Would I need to specify which one to use?

I found the trigger below online but it's not working. 
Any suggestions?

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000907dIAA

trigger createQuotePDF on Quote (after update) { List<QuoteDocument> sr = new List<QuoteDocument>(); for (Quote q: Trigger.new) if (q.Status == 'Presented'){ sr.add (new QuoteDocument( QuoteId = q.Id, VersionData = 'someValue')); } insert sr; }
AbhinavAbhinav (Salesforce Developers) 
HI Michelle ,

I checked the link with below code mentioned are you getting any issue?
 
trigger createQuotePDF on Quote (after update) {

List<QuoteDocument> sr = new List<QuoteDocument>();
    for (Quote q: Trigger.new)
         if (q.Status == 'Draft'){
                 sr.add (new QuoteDocument(
                 QuoteId = q.Id,
                 document = Blob.toPDF('Your Contents Here')));  
         }
   insert sr;
 }

Thanks!
ravi soniravi soni
hy ,
try below code.
trigger createQuotePDF on Quote (after update) { 
List<QuoteDocument> sr = new List<QuoteDocument>(); 
for (Quote q: Trigger.new) {
	if (q.Status == 'Presented'){ 
sr.add (new QuoteDocument( QuoteId = q.Id, 
 VersionData = 'someValue'
  //,document = Blob.toPDF('Your Contents Here'))
  ));
 }
}
if(sr.size() > 0){
insert sr;	
} 
 
 }
don't forget to mark it as best answer.
Thank you
 
Michelle PoirierMichelle Poirier
@veersoni I will try thyis code and keep you posted thanks! Where it says "Your Content Here" Am I supposed to change that to something or leave as is?
@
Abhinav  I used the code but nothing happens when I create/update the quote. The PDF does not get generated. 
Michelle PoirierMichelle Poirier
@veer soni I got this error with the trigger: 
Error: Compile Error: Field does not exist: VersionData on QuoteDocument at line 5 column 9, any suggestions?