URL Builder Button Tool
The URL Builder Button is a tool that allows a Community Hub Admin to create a custom link through a button on a card that can pre-populate information on another page or an authorized 3rd party site.
At this time, the URL Builder Button Tool is a Support Enabled Feature. If this is something you are interested in, please reach out to Nimble AMS Support. You will not be able to complete following steps until this feature has been enabled.
Creating a URL Builder Button
Creating a URL Builder Button with the Current User's Salesforce ID
As an example, if you would like to create a URL Builder button that accesses a site with a query string parameter appended to a specified URL, you would need the query string parameter to be set to the current logged in user's account ID.
- Defining the Button
- Navigate to the ‘Community Hub Setup’ App and select Buttons from the top navigation menu.
- Create a new button.
- Provide a button name.
- Set the class to URLBuilderButton.
- Provide a label for the button's text.
- Optional: Indicate the location for the button on the page.
- In the URL field, enter the web address.
Click Save.
Setting the Target field will not have an impact on the redirect process. The user will be redirected to the URL specified in their current browser window/tab.
- Defining The Parameter
- From Setup, search ‘metadata’ in the quick find selection and select Custom Metadata Types.
- Find the Button URL Parameter metadata type and click on the Manage Records link.
- Click on the New button to create a new button URL parameter record.
- Provide a name for the parameter in the Label field.
- Specify the name of the parameter in the Button URL Parameter Name field. This can be the same as the Label value but it cannot contain any spaces or other punctuation characters.
- Check the Active checkbox.
- Since this is for the account ID, you can leave the query name blank.
- Set the query string parameter name in the Parameter Name field. This is the value that will be included in the query string of the URL.
- Set the Parameter Value field to {!CurrentAccountID}.
- Click on the lookup icon and select the button you created in the previous steps.
- Click Save.
Add the Button to Community Hub Content
Return to Community Hub Setup.
Select the page you want to include the button.
Add the button to one or more cards on the page.
Save the content.
Creating a URL Builder Button with Static Parameter Values
If you would like to create a URL Builder button that accesses a site with a query string parameter appended to a specified URL, this query string parameter will not be based on the current user or any other source of data but is instead a static value. However, the creation and inclusion of the button on a page is the same noted above section - the only difference is in the setup of the button parameter metadata record.
Define the Static Parameter
Access Salesforce Setup and type metadata into the quick find selection to access the Custom Metadata Types.
Find the Button URL Parameter metadata type and click on the Manage Records link.
Click on the New button to create a new button URL parameter record.
Provide a name for the parameter in the Label field.
Specify the name of the parameter in the Button URL Parameter Name field. This can be the same as the Label value but it cannot contain any spaces or other punctuation characters.
Since this is for the account ID, you can leave the query name blank.
Check the Active checkbox.
Set the query string parameter name in the Parameter Name field. This is the value that will be included in the query string of the URL.
Set the Parameter Value field value to the appropriate value.
Click on the lookup icon and select the button you created in the previous steps.
Click Save.
Creating a URL Builder Button using a Query Record
If you would like to create a URL Builder button that accesses a site with a query string parameter appended to a specified URL, then this parameter's value should be based off of an accessible query record.The creation and inclusion of the button on a page is the same as above. The only difference is in the setup of the button parameter metadata record; the remainder of the steps are as outlined in the initial example above.
Define the Dynamic Parameter Using a Query Record
Access Salesforce Setup and type metadata into the quick find selection to access the Custom
Metadata Types.Find the Button URL Parameter metadata type and click on the Manage Records link.
Click on the New button to create a new button URL parameter record.
Provide a name for the parameter in the Label field.
Specify the name of the parameter in the Button URL Parameter Name field. This can be the same as the Label value but it cannot contain any spaces or other punctuation characters.
Check the Active checkbox.
Set the Query Name to the name of the query record to use (query record setup is outside the scope of this guide).
Set the query string parameter name in the Parameter Name field. This is the value that will be included in the query string of the URL.
Set the Parameter Value field to the field name to grab from the query.
Click on the lookup icon and select the button you created in the previous steps.
Click Save.
Creating a URL Builder Button Using the Record ID
The parameter button can be used in conjunction with the current record or associated record as in the case of record lists and record sets. These objects include a reference to the related object's context. The remainder of the needed steps are noted in the original example above.
Define the Dynamic Parameter for the Current Record ID
Access Salesforce Setup and type metadata into the quick find selection to access the Custom Metadata Types.
Find the Button URL Parameter metadata type and click on the Manage Records link.
Click on the New button to create a new button URL parameter record.
Provide a name for the parameter in the Label field.
Specify the key for the parameter in the Parameter Name field.
Enter {!RecordId} in the Parameter Value field. This will indicate the button should use the record Id of the object identified in the context.
Check the Active checkbox.
Click on the lookup icon and select the button you created in the previous steps.
Click Save.
Referencing a Merge Field in a Query
The URL Builder Button has special support for passing its record Id into a query. Record Id is a property buttons can use when placed on certain types of cards (notably Record List). To access the record Id in a query, simply place {!RecordId} wherever it should be referenced in the WHERE clause. {!CurrentAccountId} is also supported.
Parameterizing the URL Path
Some websites use a URL scheme like https://example.com/resource/{id}/additional/ , where {id} is a dynamic value. This dynamic value is not part of the query parameter string (i.e. there is no ? or &). To handle these cases, a couple adjustments are needed:
The URL on the Button record needs at least one string format token
e.g. https://example.com/resource/{0}/dostuff/They must be in order, and the first must be {0}
Any number are supported e.g. https://example.com/resource/{0}/dostuff/{1}/another/{2}/{3}/
The ButtonUrlParameter metadata records that provide the values have two differences:
The Type field needs to be changed to "Path Parameter"
The Parameter Name field needs to simply be a number corresponding to which place it should be
substituted e.g. 0 or 1A ButtonUrlParameter of Type Path Parameter and Parameter Name of 0 will have its Value substituted
for the {0} in the URL
Dynamically Determining the URL
For each potential URL, you need to create a Dynamic Url Setting custom metadata record.
Do you have a single button that needs to go to two or more different URLs depending on certain conditions? If so, this is the section for you. The way the button determines which URL to use is as follows:
Dynamic URL Setting custom metadata records have three fields: Field, Data Source, and Value.
Field is the API name of a field on an object, e.g. NU__Member__c
That field is read from the first object returned by the Data Source.
If the value of the field returned by the data source matches the Value of the Dynamic URL Setting, that settings URL will be used.
If none of the Dynamic URL Settings conditions are met, the URL on the Button custom metadata record is used.
Access Salesforce Setup and type metadata into the quick find selection to access the Custom Metadata Types.
Find the Dynamic URL Setting metadata type and click on the Manage Records link.
Click on the New button to create a new Dynamic URL Setting record.
Provide a name for the setting in the Label field.
Use the same value without spaces for the Dynamic URL Setting Name.
Choose the Button this setting corresponds to.
Specify the URL in the URL field.
Specify the Data Source to use for determining if this records URL is the one that should be used.
Set the Field to the API name of the field that the URL should look at.
Set Value to the expected value of the field.
Optionally, change the Sort Order. This is only necessary if some conditions need to be checked prior to others.
The first Dynamic URL Setting whose condition is met is the one that will be used.
The Dynamic URL Strategy can be ignored - it defaults to DataSourceFieldDynamicUrlStrategy which is the only option currently supported.
Click Save.
URL Builder Button with Multiple Parameters (Example)
For this example we will satisfy the use case of a button that should include three query string parameters, as defined in the table below:
Parameter Name | Source |
---|---|
Id | The current logged in user's Salesforce ID. |
In | The current logged in user's last name. |
Passcode | A static value used for a remote site authentication |
Create the Button
We will start with the creation of the URL Builder Button definition in Community Hub Setup. Be sure to indicate URLBuilderButton as the button class.
Learn more about Creating Buttons
Create the Parameters
Next, create each of the parameters by adding new Button URL Parameter metadata type record. Use the table below as a reference for each entry.
Record Field | Current ID Parameter | Passcode Parameter | Last Name Parameter |
---|---|---|---|
Label | Current Account ID | Pass Code | Last Name |
Button URL Parameter Name | CurrentAccountId | Pass_Code | Last_Name |
Active | Checked | Checked | Checked |
Query Name | <The name of your query> | ||
Parameter Name | Id | passcode | In |
Parameter Value | {!CurrentAccountID} | ABC54321 | LastName |
Parent Button | ExternalSSOButton | ExternalSSOButton | ExternalSSOButton |
Add the Button to the Page
On a new or existing page, the button created in the first step can be added to any card that supports buttons. When the page loads and the button is clicked, the user will redirect to the specified URL with the ID, Pass Code, and Last Name parameters filled in.
Automatic Redirection with Parameters
Using the Redirect Page Handler in Conjunction with URL Builder Buttons any URL Builder button you create can be manually invoked on pages they are displayed or automatically through a special redirect handler in Community Hub. All that is required for automatic invocation is to use the special /redirect handler in Community Hub and specify the button you wish to execute by its name. The URL to call follows the format: https://<Community Hub URL>/communityhub/redirect?button=<button name>
If a user is not already authenticated, the redirect handler will ensure they log in before redirecting them to the target URL.
Redirect Example
The use of URL Builder Buttons with the redirect handler works very well for simple single sign on (SSO) operations that require the external site to capture some basic information of the logged in user without the need for complex integrations or workflows. The external site just needs to call on the /redirect page and specify the special URL Builder Button that will return the authenticated user to their site with query string parameters indicating user identity, authorization codes, or any other required parameter.
The button's name used in the redirect handler is case sensitive. You must ensure the button name in the redirect URL matches the name defined in the button configuration exactly. Button invocation using the redirect handler is not inhibited by access controls. If a button has an access control setting, the logged in user can still invoke the button's redirect actions regardless whether the individual meets the access control requirements.
Page Submission
If you need a button that submits the page the same way NC.SubmitButton does, use UrlBuilderSubmitButton as the class instead of UrlBuilderButton.
Community Hub Template Viewer
Using the URL Builder Button Tool, you can make Nimble Create Templates easily available for your constituents to access in Community Hub.
Requirements
Ensure the Community Hub Login User has:
- Object Permissions: Read access and View All for NUTPL__Template__c
- Visualforce Page: DynamicTemplate
As a general rule you should never give a profile the "View All" permission for an object. However in this case, it is necessary for Templates to function in this scenario.
Usage Guide
Basic Use
Create a button or nav that links to /apex/DynamicTemplate?templateName=My+Template¶m1=someId
The only required parameter is the template name (replace spaces with +). Nearly all templates however take in a record id as a parameter, which you may specify using the URL. As an alternative, you can use Custom Parameters, as noted below.
Adding Custom Parameters
Use in conjunction with the URL Builder Button Tool to pass parameters into the template.
Changing the Orientation
Set the "landscape" URL parameter to "true" (i.e. add &landscape=true) to output in landscape mode, or, "false" to output in portrait mode. If the parameter is not set it will default to portrait mode.
The output may not show as the correct orientation in a print preview window. If on Windows and using "Microsoft Print to PDF" it is not possible to change the orientation.
Rendering as PDF
Set the "renderAs" URL parameter to "pdf" (i.e. add &renderAs=pdf) to render the template as a PDF, or, set it to "html" to output in html. If the parameter is not set it will default to HTML. As an example, you could use the following format:
/apex/DynamicTemplate?templateName=My+Template¶m1=someId&RenderAs=pdf
Custom styles are currently broken for PDFs. It is recommended to output to HTML and then use the browser's print function to output PDF files.