Template Provider Class
  • 14 May 2024
  • 1 Minute to read
  • Dark
    Light

Template Provider Class

  • Dark
    Light

Article summary

The Deal Manager Template feature allows a user to populate a new Deal Manager document with values and lines from an existing Deal Manager document that was previously designated as a Template.

For more information on the Template feature, see Configure templates.

The TemplateProvider hook can filter all active Deal Manager Templates that a user can choose when applying a template to a Deal Manager document they are working on. The hook has access to all of the attributes of the Deal Manager document that the template will be applied to, as well as all attributes of active Deal Manager Templates. The hook can use these attributes to allow a user to pick a template only from a subset determined by the business rules of the implementation.

This hook is called when the List of all available Deal Manager Templates is presented in a Lightning Record Page.

Apex hook class

  • It must implement the TemplateListProvider interface.
  • It must have a global access modifier.
  • You must specify the Apex hook class name in the Template Provider Class Name field of the Copy Configuration in the Custom Metadata Type.

Interface definition

global interface TemplateListProvider
{
    List<Id> getTemplateIds(Id sObjectId, String sObjectType);
}

Example 1: Class implementation

This example pulls the Region and the Year from attributes attached to the Current Agreement being worked on and returns templates that have the same Year and Region values in the respective attributes on the template.

global with sharing class sskTemplateProvider implements zpl.TemplateListProvider{
  global List<Id> getTemplateIds(Id sObjectId, String sObjectType) {
  ID currentRecord = sObjectId;
  String agreeRegion = [SELECT ssk_Acct_Sales_Office__c FROM Contract WHERE Id = :currentRecord].ssk_Acct_Sales_Office__c;
  String agreeYear = [SELECT ssk_Term_Year__c FROM Contract WHERE Id = :currentRecord].ssk_Term_Year__c;   
  Map<Id, zpl__Template__c> templates = new Map<Id, zpl__Template__c>([SELECT Id FROM zpl__Template__c WHERE ssk_Term_Year__c = :agreeYear AND ssk_Sales_Office__c = :agreeRegion]);
  return new List<Id>(templates.keySet());
  }
}

Example 2: Class implementation

global with sharing class TestTemplateProvider implements TemplateListProvider{
 
 
    global List<Id> getTemplateIds(Id sObjectId, String sObjectType) {
        Map<Id, Template__c> templates = new Map<Id, Template__c>([SELECT Id FROM Template__c]);
 
 
        return new List<Id>(templates.keySet());
    }
}

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.