Custom Contexts

By default ResinFiles uses the Context provided by Salesforce in the form of a Signed Request. It is possible to override some of these parameters to help match your folder structure. We modify the VisualForce to achieve this.

Default VisualForce for an Account

  • The Account’s name will be passed in
  • The Account’s name will be used as the folder name to look for

    <apex:page showHeader="false" standardController="Account">
    <apex:canvasApp
        applicationName="ResinFiles"
        parameters="{
            recordName: '{!JSENCODE(account.name)}',
            actualHeight: document.documentElement.clientHeight
        }"
        width="100%"
        height="800px"
        scrolling="no" />
    </apex:page>
    

VisualForce to use a custom Folder Name

  • The Account’s name will be passed in
  • A custom field defines the folder name to look in Google Drive for.

    <apex:page showHeader="false" standardController="Account">
    <apex:canvasApp
        applicationName="ResinFiles"
        parameters="{
            recordName: '{!JSENCODE(account.name)}',
            recordFolderPath: [
                '{!JSENCODE(account.Folder_Name__c)}'
            ],
            actualHeight: document.documentElement.clientHeight
        }"
        width="100%"
        height="800px"
        scrolling="no" />
    </apex:page>
    

VisualForce to use a custom folder path

  • The Opportunity’s name will be passed in
  • Opportunities are nested within the Account’s folder.
    e.g. My Drive > Salesforce > Accounts > Dickenson Plc > Opportunities > Bricks and Mortar

    <apex:page showHeader="false" standardController="Account">
    <apex:canvasApp
        applicationName="ResinFiles"
        parameters="{
            recordName: '{!JSENCODE(account.name)}',
            recordFolderPath: [
              '{!JSENCODE(opportunity.account.name)}',
              'Opportunities',
              '{!JSENCODE(opportunity.name)}'
            ],
            actualHeight: document.documentElement.clientHeight
        }"
        width="100%"
        height="800px"
        scrolling="no" />
    </apex:page>
    

Apex Class to use a custom folder path

Sometimes you need slightly more complicated logic to map your Records to your Google Drive folders. For example you may store archived Opportunities in a separate folder structure.

Imagine the following folder structure:

  • My Drive > Salesforce > Current Opportunities > Rooiboos Tea Pty
  • My Drive > Salesforce > Archived Opportunities > Ceylon Tea SR Ltd

To get this to work we’ll need to create an Apex class withe the following contents:

public class RFOpportunityMapping {
    private final Opportunity oppo;

    public RFOpportunityMapping(ApexPages.StandardController controller) {
        controller.addFields(new List<String>{'StageName'});
        this.oppo = (Opportunity)controller.getRecord();
    }

    public String getRecordFolderName() {
        if (oppo.StageName == 'Delivered' ||  oppo.StageName == 'Returned' ||  oppo.StageName == 'Closed Lost'){
            return 'Archived Opportunities';
        }

        return 'Current Opportunities';
    }
}

Then we’ll need to add extensions to our VisualForce. For example:

<apex:page showHeader="false" standardController="Opportunity" extensions="RFOpportunityMapping">
    <apex:canvasApp
        applicationName="ResinFiles"
        parameters="{
            recordName: '{!JSENCODE(opportunity.name)}',
            recordFolderPath: [
              '{!JSENCODE(recordFolderName)}',
              '{!JSENCODE(opportunity.name)}'
            ],
            actualHeight: document.documentElement.clientHeight
        }"
        width="100%"
        height="800px"
        scrolling="no" />
</apex:page>

Notes:

  • We reference recordFolderName, not getRecordFolderName inside the VisualForce.
  • You’ll need to enable Custom Paths in the “System Configuration” tab