Use S-Docs with Salesforce Sites

Introduction

S-Docs can be used in Salesforce Sites too! In this guide, we will be setting up this functionality for a particular Salesforce object (you will need to follow the steps in this guide for each object you are enabling S-Docs with Sites for). To do so, all we have to do is create a button that will show up for your Site users and add it to an object’s page layout.

communities 01
This button is not unique to communities; it will also exist in our production org and operate exactly the same as an ordinary S-Docs button. This means if we already have an S-Docs button, we will be replacing it with a new button that can be used by Site users as well as users in our production org.

communities 02

Step 1: Create the S-Docs for Sites Button

In this step, we will be creating a button that will enable the use of S-Docs with Salesforce Sites for a particular object. In this example, we will be creating the button for an opportunity.

  1. You will first need to navigate to the “Buttons, Links, and Actions” page for the Salesforce object you would like to create a Sites button for.
Note: If you’re creating the button for a custom object, please follow the instructions for part (a). If you’re creating the button for a standard object, please follow the instructions in part (b).

a.) Custom Objects

Navigate to Setup > Build > Create > Objects.

communities 03
Find the name of the custom object you would like to create the button for and click the name of this object (do not click the Edit button). In this example, we will be creating the button for the Check object, a custom object representing the data for a standard business check.

communities 04
Next, a page will display for your custom object.

Please take note of the API Name at this point, as you will require it in later steps.

The API Name is often just the “Object Name” appended with __c (note the two underscores), but sometimes this is not the case, so please take note of that here. In the case of our custom Check object, we will note that our API Name is Check__c.

communities 05
On the page for your custom object, scroll down to “Buttons, Links, and Actions” and click New Button or Link.

communities 06
This concludes part (a).

b.) Standard Objects

Navigate to Setup > Build > Customize > YourObjectNameHere > Buttons, Links and Actions. In this example, we will be finding the “Buttons, Links, and Actions” page for an Opportunity.

communities 07
Once you’re on the “Buttons, Links, and Actions” page for your standard object, click New Button or Link.

communities 08
This concludes part (b).

  1. We will now complete the “New Button or Link” page. Here is how the finished page might appear:


Here’s what to fill in:

Label: Create Documents (S-Docs)
Name: Create_Documents_S_Docs
Display Type: Detail Page Button
Behavior: Display in existing window without sidebar or header
Content Source: URL

Finally, paste the following code into the “Custom button or link editor.”

{!URLFOR($Site.BaseCustomUrl+'/'+
SUBSTITUTE($Site.Prefix, '/', '') +
IF ( OR(ISBLANK($Site.Prefix),$Site.Prefix='') ,
'apex/SDOC__SDCreate1?id='+ChangeToYourObjAPIName.Id+'&Object=ChangeToYourObjAPIName&doclist=Template Name&site='+IF(ISBLANK($Site.Prefix),'DEFAULT',$Site.Prefix),
'/apex/SDOC__SDCreate1?id='+ChangeToYourObjAPIName.Id+'&Object=ChangeToYourObjAPIName&doclist=Template Name&site='+$Site.Prefix))}

Again, please make sure that all appearances of “ChangeToYourObjAPIName” have been changed to your object’s API name. Click Save to finish the button.

Note: The button code above includes the doclist parameter, which allows you to specify a comma-delimited list of template names or IDs to automatically generate when the button is clicked (as opposed to the user selecting a template). You can remove this parameter if you'd like users to select their own templates.

Step 2: Add the S-Docs for Sites Button to the Page Layout

Now, all we have to do is add the button we just created to our object’s page layout.

  1. You will first need to navigate to the “Page Layout” page for the Salesforce object you would like to add the button to.
Note: If you’re creating the button for a custom object, please follow the instructions for part (a). If you’re creating the button for a standard object, please follow the instructions in part (b).

a.) Custom Object Page Layout

Navigate to Setup > Build > Create > Objects.

communities 10
Find the name of your custom object and click the name of this object (do not click the Edit button). In this example, we will be adding the button to a Check’s page layout.

communities 11
On the page for your custom object, scroll down to “Page Layouts” and click Edit next to “YourObjectName Layout.”

communities 12
This concludes part (a).

b.) Standard Object Page Layout

Navigate to Setup > Build > Customize > YourObjectNameHere > Page Layouts. In this example, we will be finding the “Page Layouts” page for an Opportunity.

communities 13
Now click Edit next to “YourObjectName Layout.” (There may be other layouts, such as “YourObjectName Layout SDoc”. Do not edit these; only edit “YourObjectName Layout.”)

communities 14
This concludes part (b).

  1. Now we can add the button to the page layout. Drag the button you created in Step 1 into the “Custom Buttons” box. If there is already an S-Docs page button here, you may remove it from the “Custom Buttons” box by dragging it into the toolbar you pulled your Create Documents (S-Docs) button from. Your new button works the same as the old S-Docs button, except now it can be used by Sites.

communities 15
Here’s how the finished page will appear.

communities 16
Click Save and you’re all done! You should now have an S-Docs button on your object’s page that can be used by users in your communities, as well as users in your production org.

Using Automation with Sites Users

If you require your Site users to insert S-Docs Jobs (for example, by invoking document automation through a Flow or Apex trigger), take the following into account.

ContentVersions inserted by Community users must not have a null NetworkId (Community ID) field. While this field is normally auto-populated, in some instances population fails.

To correct this, you can configure your Flow, Apex trigger, or Process to set the S-Docs Jobs NetworkId field to the following:

Network.getNetworkId();

This will ensure that the ContentVersion NetworkId field is always populated, and S-Docs Jobs inserted by Site users will not fail.

Tags: , , ,

Was this helpful?