Sunday, 13 December 2020

How to generate QR code for Survey Invitation in Salesforce Platform Survey

 Easy steps to generate QR code for Survey Invitation Link



1) Create your Survey using Salesforce Platform Survey.

2) Once done activate it.

3) Open the send radio button in Survey builder.

4) Generate the default invitation.

5) There you will see a 'Generate QR Code' button next to the copy link button.

6) Click on the 'Generate QR Code' button and it will download a .png file containing the QR code for your default Survey Invitation.

7) Distribute the QR code using any channel you want.


You can also check out a video tutorial for it here:




Sunday, 6 December 2020

FinServ Optimize Record Rollups: Sample Apex Code on how to use HouseholdAssignmentBatchable batch job.


A sample code on how to use HouseholdAssignmentBatchable class from the anonymous window.


One you enabled Optimised Roll-ups with Winter 21 - Optimize Record Rollups
And as per this article: https://help.salesforce.com/articleView?id=release-notes.rn_fsc_rollup_config_custom_setting.htm&type=5&release=228

If you enabled the new Record Rollup Optimization (Beta) org preference, use the new HouseholdAssignmentBatchable batch job instead of GroupAssignmentBatchable to roll up records in batches.




Below is a sample code to how to run the HouseholdAssignmentBatchable batch job:



Option 1

To execute the job for a single object with configuration defined in the custom setting use the following signature

FinServ.HouseholdAssignmentBatchable.runJob('Task');

Option 2

To execute the job for multiple objects sequentially with configuration defined in the custom setting use the following signature



FinServ.HouseholdAssignmentBatchable.runJob(new List<String> {'FinancialAccount__c', 'Task'});

 Option 3

To execute the job for one or more objects with overridden settings,  New instances of class FinServ.HouseholdAssignmentBatchable.RecordRollupConfig need to be constructed and passed to FinServ.HouseholdAssignmentBatchable.runJob(List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig> recordRollupConfigs).


FinServ.HouseholdAssignmentBatchable.RecordRollupConfig provides two constructors:

//startTime, endTime can be set to null.
//When set to null that filter is not applied when querying the object.

//Constructor 1:
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime)

//Constructor 2:
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime, Integer scope)



Sample code.


FinServ.HouseholdAssignmentBatchable.RecordRollupConfig recordRollupConfigFinancialAccount = new FinServ.HouseholdAssignmentBatchable.RecordRollupConfig('FinancialAccount__c', DateTime.newInstance(2009, 3, 4, 21, 2, 2), null, 500);

FinServ.HouseholdAssignmentBatchable.RecordRollupConfig recordRollupConfigCase = new FinServ.HouseholdAssignmentBatchable.RecordRollupConfig('Case', null, null);

List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig> recordRollupConfigs = new List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig>{recordRollupConfigFinancialAccount, recordRollupConfigCase};

FinServ.HouseholdAssignmentBatchable.runJob(recordRollupConfigs);

// Note: To run concurrently for multiple objects you can call FinServ.HouseholdAssignmentBatchable.runJob() multiple times.
// For example, see the sample below.

FinServ.HouseholdAssignmentBatchable.runJob('Task');
FinServ.HouseholdAssignmentBatchable.runJob('Claim');


            

Sample code on how to execute GroupAssignmentBatchable Finserv (FSC) apex Job (Salesforce )


Record rollup batch job execution

GroupAssignmentBatchable 

Option 1

To execute the job for all objects with configuration defined in the custom setting use the following signature.
Database.executeBatch(new FinServ.GroupAssignmentBatchable());

Option 2

To execute the job for one or more objects with overridden settings, New instances of class FinServ.GroupAssignmentBatchable.RecordRollupConfig need to be constructed and passed to FinServ.GroupAssignmentBatchable.runRecordRollupJob(List<FinServ.GroupAssignmentBatchable.RecordRollupConfig> recordRollupConfigs).

FinServ.GroupAssignmentBatchable.RecordRollupConfig provides two constructors:

//startTime, endTime and scope can be set to null.
//When set to null value the values are read from the custom setting.

//Constructor 1:
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime)


//Constructor 2
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime, Integer scope)

Sample code:

FinServ.GroupAssignmentBatchable.RecordRollupConfig recordRollupConfigFinancialAccount =new FinServ.GroupAssignmentBatchable.RecordRollupConfig('FinancialAccount__c', DateTime.newInstance(2009, 3, 4, 21, 2, 2), null, 500);

FinServ.GroupAssignmentBatchable.RecordRollupConfig recordRollupConfigCase =new FinServ.GroupAssignmentBatchable.RecordRollupConfig('Case', null, null, null);

List<FinServ.GroupAssignmentBatchable.RecordRollupConfig> recordRollupConfigs = new List<FinServ.GroupAssignmentBatchable.RecordRollupConfig>{recordRollupConfigFinancialAccount, recordRollupConfigCase};


FinServ.GroupAssignmentBatchable.runRecordRollupJob(recordRollupConfigs);




Create Action Plan record through Apex Code



Below is a Sample code on how you can create Action Plan and its pre-requisite
records step-by-step:


Refer Salesforce Action Plan document to know more details about Action Plan.

//Execute below code in anonymous console or as a method

ActionPlanTemplate apt = new ActionPlanTemplate();
apt.Name = 'AP_Teamplate_Apex';
apt.ActionPlanType = 'Industries';
// You can provide any object here for which AP is Supported
apt.TargetEntityType = 'Account';

System.debug('before ActionPlanTemplate insert');
insert apt;

ActionPlanTemplateVersion aptv = [select Id, Status from ActionPlanTemplateVersion where Status = 'Draft' and
ActionPlanTemplateId = :apt.Id]
ActionPlanTemplateItem apti = new ActionPlanTemplateItem();
apti.ActionPlanTemplateVersionId = aptv.Id;
//apti.DisplayOrder = 1;
apti.Name = 'AP_Teamplate_Item_Apex';
apti.ItemEntityType = 'Task';
insert apti;

aptv.Status = 'Draft';
System.debug('before ActionPlanTemplateVersion update');
update aptv;
ActionPlanTemplateItemValue aptiv=new ActionPlanTemplateItemValue();
aptiv.ActionPlanTemplateItemId=apti.id;
aptiv.ItemEntityFieldName='Task.ActivityDate';
aptiv.Name= 'ActivityDate';
aptiv.ValueFormula =' StartDate + 360';
insert aptiv;
aptiv=new ActionPlanTemplateItemValue();
aptiv.ActionPlanTemplateItemId=apti.id;
aptiv.ItemEntityFieldName='Task.Priority';
aptiv.Name= 'Priority';
aptiv.ValueLiteral='Normal';
insert aptiv;
aptiv=new ActionPlanTemplateItemValue();
aptiv.ActionPlanTemplateItemId=apti.id;
aptiv.ItemEntityFieldName='Task.Subject';
aptiv.Name= 'Subject';
aptiv.ValueLiteral='New test task';
insert aptiv;
aptv.Status = 'Final';
System.debug('before ActionPlanTemplateVersion update');
update aptv;
System.debug([select Id, Name, Status from ActionPlanTemplateVersion]);
List<ActionPlanTemplateVersion> tempVerList = [select Id from ActionPlanTemplateVersion where Status = 'Final' limit 1];
System.assertEquals(1, tempVerList.size());
List<Account> accList = [select Id from Account limit 1];
System.assertEquals(1, accList.size());
ActionPlan ap = new ActionPlan();
ap.Name = 'Test AP for Test Coverage';
System.debug('Adding template version id as '+tempVerList.get(0).Id +' ----');
ap.ActionPlanTemplateVersionId = tempVerList.get(0).Id;
ap.ActionPlanType = 'Industries';
ap.TargetId = accList.get(0).Id;
ap.ActionPlanState = 'Not Started';
ap.StartDate = System.today();
System.debug('before ActionPlan insert'+ap + '----------');
insert ap;

    How to embed a Survey component in a community page


    Follow the below steps to Embed Salesforce Survey component on the community page:
    Pre-requisites



    1) Go to Setup-->All Community and create a new community by choosing any template.


    2) Once the community gets created, click on the builder.


    3) In the builder, click on the gear icon and then click on the guest user profile.



    4) Edit the guest user profile and provide Read Access on Survey and Survey Invitation objects and Read, Create and Edit on Survey Response Object, and save.







    5) Then in the community builder click on the publish button on the top right to get your community published.


    6) Now go to setup --> All Community --> Open workspaces for the community you just created, open Administration, and click on "Activate Community"






    7) Once your community is activated, add it to survey settings by going to setup --> Survey Setting and add as below under "Select the default community for creating public survey invitations."









    8) Once the community set-up part is done, create a Survey, and activate it once done.


    9) Open the Survey builder for the above Survey and generate the default Survey Invitation URLs for "Participants outside your company"








    Notice- The invitation URL domain is the same as your default community domain which you had set in the Survey settings in step 7.


    ** Also if you want guest users to take that survey, then 'Check' the option 'Don't require authentication'


    10) To embed the survey in your community pages, go to setup --> All Community --> Open workspaces for the community you created above and open the builder.


    11) In community builder, click on the first lightning icon on the top left and type survey in the search bar.












    12) Drag and drop the Survey component to the block you want to place it, and then choose the Survey name (of the Survey you created above) in the component configuration details.









    13) Now click on the publish button on the top right to save the new changes.




    14) Open the community page in runtime and you will be able to see the survey component rendered on your community in runtime.


    Note- For each new Community you want to embed a Survey Component, you need to follow steps 3-14 again for that community for it to work. 

    Guest user profile for each community is different, so we need to ensure for any new Community's Guest user profile is granted all Survey Objects related permissions again, and also default Survey Invitation (based on new Community's domain) is also required to be generated for it to work.  
















    What is a Salesforce Object and how to differentiate between Standard and Custom Salesforce Objects.





    • Salesforce Objects are nothing but a database table in the background.
    • When you create an object, a corresponding DB table is created in the backend by the Salesforce platform.

    • When you create records for any object, that data gets inserted into the corresponding DB table.

    • There are two types of salesforce objects
      • Standard - The ones shipped out of the box by salesforce
      • Custom - The one which we create on the Org.

    • How to differentiate between Standard and Custom Salesforce Objects?
      • Go to Setup --> Object manager
      • Open the Object you want to check
      • In Object details, check the API name of the Object:
        • If it has __c appended in the end then it is a custom object.
        • If it does not have __c appended, then it is a standard object.
    Sample Standard Object:



    Sample Custom Object:






    How to make a question conditionally visible based on previous question response in Salesforce Survey

    Below shows how you can make a Survey question conditionally visible


     Let say I have a Survey and it has two questions:

    1. Rate our product (out of 5 stars) 
    2. How would you like us to improve it for you? (long text question)
    Now I want to show question 2 only if any user rated my product 3 or less.


    Steps 1:

    Create a Survey with both the questions:







    Step2:

    Go to Question 2 and click on the 'display logic' button :






    Step3:

    In 'Select Condition' - Choose  'All Conditions are met'
    In 'Question' -  Select the first question 'Rate our product!'
    In 'Operator' - Select 'is less than or equal to'
    In 'Response' - Select '3'



     


    And then click on the 'Save logic' button.


    This will make question 2 appear only for those users who rated the product 3 or less.


    You can also watch a tutorial on this below, it also includes how to use branching logic along with display logic:










    How to generate QR code for Survey Invitation in Salesforce Platform Survey

     Easy steps to generate QR code for Survey Invitation Link 1) Create your Survey using Salesforce Platform Survey. 2) Once done activate it....