“Save” your Document Action to Generate Custom Code: 

Once you have completed all needed fields in document action, click “Save” to save your Document action. A completed Document Action will auto-generate Action ID and Button/Link Code:

  • Button/Link Code. Code for the Button or Link that will be used for Document generation (copy this value to your clipboard, you will need it in the next step).
    • IMPORTANT NOTE for LEX USERS Using Opportunity Object: If you created the document action in Lightning experience and using Opportunity as your base object, there will be an extra value added to custom code in front of your object ID in document action: http://. So you need to remove this from button code when pasting into custom button. This will only happen if you create the document action in Lightning Experience, this will not happen if you create in Classic and use in Lightning Experience.
    • For example, the final button code at bottom of saved document action will say
      “/apex/rsdoc__GenerateDocument?id={!http://Opportunity.Id}&templateId=GDT-000000&attach=true&output=pdf&emailAction=Preview&emailTo=&emailTemplate=&emailToAdditional=&emailCC=&emailBCC=” though when pasting your code into custom button, you will want to remove this added hyperlink to object (http://) so the final code you would paste correctly is:
    • In addition you can manually setup what Salesforce fields to update upon Document Generation by adding in the end of this code next variables: &fieldtoupdate1=StageName&fieldtoupdatevalue1=Proposal Sent, where:
      • &fieldtoupdate1= API Name of the field that you want to update (Opportunity stage in our Example)
      • &fieldtoupdatevalue1=New value of the field (In our example new value will be “Proposal Sent”)
      • Put  consequential  after variable if you want to update more than one field: &fieldtoupdate1=API_Field1&fiedtoupdatevalue1=Field1_NewVale….&fieldtoupdateN=API_FieldN&fiedtoupdatevalueN=FieldN_NewVale*field to update cannot be used with boolean fields, like checkbox