Showing posts with label Configuration. Show all posts
Showing posts with label Configuration. Show all posts

02 December 2016

Community Cloud Certification Tips




I decided to take to community cloud certification before the end of this year because I think there are a lot of opportunities in the market right now that requires specialisation on implementing communities. Having been involved in the old customer/partner portal implementations as well as a community implementation 2 years ago when it was still in beta, I felt that this is the best time to take it since the functionality is growing every release.

Anyway, this post is about what I think you should be aware of and take time to review when you take the exam and so that you can pass it.
  1. Understand data access using sharing set, sharing group, OWD
  2. Opening data access using super user access (for partner and customer community plus licenses)
  3. What objects each community license types provides access
  4. Difference between Private and Unlisted groups for community collaboration
  5. Live agent setup with Communities
  6. Setting up multi-language with Communities
  7. Providing public access to Communities
  8. Benefits of using custom domains for Communities
  9. Community limits (# of keyword in a list, # of moderation rule etc)
  10. Other specific things such as:
    1. What are the available lightning components in Home page
    2. Managing recommendations
    3. Setting up Community Logo on login page
    4. What are the scenario the welcome email will get sent 
    5. Which template is Salesforce1 ready 
    6. What type of changes can be done on the community page header
Most of the questions are scenario-based that will ask which implementation options are efficient (yes, multiple answers). There are tricky questions that will really test your Salesforce knowledge not just for Community functionalities. 

For some reason, I thought that this certification is the easiest compared to Sales and Service Cloud. I didn't get any question related to community integration like question and answer and escalate-to-case, community rollout process and measuring community success thru reports and dashboard.
     

06 April 2015

Skip Logic using Custom Permission

On my blog post last June, we discuss about using custom settings for skipping execution of triggers, validation rules and workflow rules. Today we can achieve the same logic using a feature Salesforce.com release last Summer 14.

But first, what is custom permission? Custom Permission allows us to extend a profile and custom permission access by allowing us to create our own "permission" attribute and can be optionally associated with a connected app. It's a simple yet powerful feature that can be use on a custom or generic application.

Below I created 3 custom permissions via Setup --> Develop --> Custom Permission.


Checking custom permission assignment in Apex Trigger requires querying the data from three setup objects called SetupEntityAccess, CustomPermission and PermissionSetAssignment. I have created a utility class that can be used to check if a user is assigned to any of the above custom permissions as below. The class cache the assignment in a permission set Id/DeveloperName and Boolean key/value pair where passing an Id or the custom permission developer name can return TRUE (if its assigned) or FALSE (if not assigned).



public class CustomPermissionUtil {
    private static Map<String,Boolean> permissionMap;
    
    public static Boolean hasCustomPermAccess(String devName){
        Boolean hasCustomPerm = false;
        if(permissionMap==null){
            refreshCache();
        }
        
        if(permissionMap.size()>0){
            if(permissionMap.containsKey(devName)){
                hasCustomPerm = permissionMap.get(devName);
            }
        }
        
        return hasCustomPerm;
    }
    
    public static Boolean hasCustomPermAccess(Id permId){
        Boolean hasCustomPerm = false;
        if(permissionMap==null){
            refreshCache();
        }
        
        if(permissionMap.size()>0){
            if(permissionMap.containsKey(permId)){
                hasCustomPerm = permissionMap.get(permId);
            }
        }
        
        return hasCustomPerm;
    }
    
    private static void refreshCache(){
        permissionMap = new Map<String,Boolean>();
        
        Set<Id> permissionIds = new Set<Id>();
        
        Map<Id,CustomPermission> customPermMap = new Map<Id,CustomPermission>(
                [SELECT Id, DeveloperName FROM CustomPermission 
                WHERE NamespacePrefix = null]);
        for(CustomPermission permObj : customPermMap.values()) {
            permissionMap.put(permObj.DeveloperName, false);
            permissionMap.put(permObj.Id, false);
            permissionIds.add(permObj.Id);
        }
        
        for(SetupEntityAccess setupEntObj : [SELECT SetupEntityId FROM 
                               SetupEntityAccess WHERE SetupEntityId in 
                               :permissionIds AND ParentID IN (SELECT 
                               PermissionSetId FROM PermissionSetAssignment 
                               WHERE AssigneeID = :UserInfo.getUserId())]){
                                                    
            permissionMap.put(setupEntObj.SetupEntityId, true);
            permissionMap.put(customPermMap.get(setupEntObj.SetupEntityId).
                DeveloperName,true);
        }
    }
    
}

To use in a trigger, an IF-condition must be added on top of the trigger code as below.

trigger TestAccountTrigger on Account (before update) {
    
    if(!CustomPermissionUtil.hasCustomPermAccess('Skip_Trigger')){
    // body of trigger
    }
    
}

For validation rule and workflow rules, a $Permission global variable is available for use.



So which one is better to use for our use-case? Custom Settings or Custom Permission? Below are the pros and cons.

Custom Settings 
Pro:
  • No SOQL required to retrieve the information (when using the custom settings method).
  • Custom Label global variable for formula.
Cons:
  • Bounded by Custom Setting data limit.
  • Access is managed on the custom setting section.
  • Data needs to be created on test classes.
Custom Permission 
Pro:
  • Custom Permission global variable for formula.
  • Assignment is aligned with how permission is given via Profile or Permission Set.
Cons:
  • Requires SOQL query to retrieve assignment.
Personally, I would go and use custom permission rather than custom settings not just because its a new feature but because it aligns to how we manage permissions to user. I would like to think that future enhancements would be released for the feature as well. However, I would recommend my readers to vote to this idea so that custom permission can be access as a global variable in Apex Code the same way we access Custom Labels. 

Happy coding!




16 June 2014

Unlocking the power of custom settings for data loading

Common use case when doing data load is to not to execute anything from the environment such as workflows, validation rules or apex triggers. This can only be achieve if (1) you have migrated only object you are targeting to do data load while workflow and triggers are not yet deployed or (2), workflows and triggers are inactivated which is somehow a hassle to admin or developers as they have to manually deactivate the workflow and worst deploy the inactivated triggers or (3), you explicitly includes user to skip on the workflow criteria or apex codes on triggers. Custom Settings can be used to hold configurations specific to user for skipping such automations.

Below is a sample custom settings I created with 3 fields.


I also created a small apex class that will interface with this custom settings and will be used on apex triggers.

public class AutoSkipSettings {
    
    public static boolean skipTrigger(){
        boolean skipTrigger = false; 
     
        Automation_Skip_Settings__c userSkipSetting = 
             Automation_Skip_Settings__c.getValues(UserInfo.getUserId());
        
        if(userSkipSetting <> null && userSkipSetting.Skip_Trigger__c){
            skipTrigger = true;
        }

        return skipTrigger;
    }
    
}

The apex triggers basically just extracts the custom setting value for the user and return the value of the checkbox. In this case, I'm returning the value of the Skip_Trigger__c field. Now we are ready to use the custom settings on validation and workflow rule criteria and apex trigger.

On the validation or workflow rule, the custom setting fields will be available as a global variable. Note that for workflow rule, you need to select 'formula evaluates to true' on the rule criteria section.


On any apex trigger, use the apex class created above.

trigger TestAccountTrigger on Account (before update) {
    
    if(!AutoSkipSettings.skipTrigger()){
    // do anything here
    }
    
}

Additional Notes:
  • The reason why we used hierarchy type for custom setting is so that we can have a default organization level value. 
  • The custom setting is much better than using custom object so that we save 1 SOQL query on the code and reference the field as global variable on formula