Wednesday 9 May 2018

How to fetch field permission details for all profiles in SOQL query

Here is the way to fetch field permission details for all profiles in SOQL query by using FieldPermissions object.

Query specific field permission for all Profiles:

  1. SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM FieldPermissions WHERE FIELD ='Payment__c.Firm__c' AND SobjectType = 'Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE) ORDER BY Profile.Name

PermissionsRead --> View permission for the field.
PermissionsEdit --> Edit permission for the field.

The below approach also works but the profile name will be displayed as [Object Object] in Query Editor,


  1. SELECT Parent.Profile.Name FROM FieldPermissions WHERE FIELD = 'Payment__c.Firm__c'  AND Parent.IsOwnedByProfile = TRUE AND SobjectType ='Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE ORDER BY Profile.Name

Reference:

Field Permission

Object Permission

How to fetch object permission for all profiles in SOQL query

You may be in a situation to verify object permission details for all or specific profile. So you may check object details from UI one by one by navigating each profile, and this will be time-consuming. Instead, you can fetch details by querying ObjectPermission. Here is the example,


Query specific object permission for all Profiles:

  1. SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM ObjectPermissions WHERE PermissionsRead = TRUE AND SObjectType = 'CustomObject__c') ORDER BY Profile.Name

You can check all object level permission in the query. Such as,
PermissionsRead 
PermissionsCreate
PermissionsEdit
PermissionsDelete
PermissionsViewAllRecords
PermissionsModifyAllRecords


The below approach also works but the profile name will be displayed as [Object Object] in Query Editor,

  1. SELECT Parent.Profile.Name FROM ObjectPermissions WHERE Parent.IsOwnedByProfile = TRUE AND SObjectType = 'CustomObject__c'

Reference:

Stackexchange

Object Permission

Friday 4 May 2018

Property 'userLicense' not valid in version 38.0 Salesforce

You will get below error message when you try to deploy PermissionSet with Package Version of 38.0

Property 'userLicense' not valid in version 38.0 Salesforce

Solution:

If you open your permission set metadata file you will see tag like below,
    <userLicense>Salesforce</userLicense>

From API Version 38.0 or later, then you have to change as license only.
    <license>Salesforce</license>


As per Salesforce documentation,

userLicense tag is Deprecated. The user license for the permission set. A user license determines the baseline of features that the user can access. Every user must have exactly one user license. Available up to API version 37.0. In API version 38.0 and later, use license.

Reference:
Permission Set Metadata API

How to Check if the Current/Running User has a Custom Permission in Salesforce?

FeatureManagement:

For this requirement we can use FeatureManagement.checkPermission method to identify Current/Running User has a Custom Permission. This method available from Winter 18 onwards.

checkPermission(apiName)
Checks whether a custom permission is enabled.

   Signature
      public static Boolean checkPermission(String apiName)
   Parameters
      apiName
   Type: String

Example:
  1. if(FeatureManagement.checkPermission('Chat_CustomPermission_Access')){
  2.     // Perform some logics.
  3. }

Reference:
FeatureManagement

Wednesday 28 February 2018

One Universal Schedule Class to Execute All Batch Classes In Salesforce

Are you creating schedule class for each batch class if you need to schedule that?

If yes, stop doing like that and start creating a universal (common scheduler class) like below and use it instead of creating multiple schedules.

Step 1: 
Create a universal scheduler class

  1. public class UniversalScheduler implements Schedulable{
  2.   public Database.Batchable<SObject> batchClassName{get;set;}
  3.   public Integer batchScopeSize{get;set;} {batchScopeSize = 200;}
  4.   public void execute(SchedulableContext sc) {
  5.      Database.executebatch(batchClass, batchSize);
  6.     }
  7. }


Step 2:
Let say, You have two batch classes and you want to schedule, then schedule batch class like below using UniversalScheduler class

Batch Class 1:
  1. AccountBatchProcess accBatch = new AccountBatchProcess(); // Batch Class Name
  2. UniversalScheduler scheduler = new UniversalScheduler();
  3. scheduler.batchClass = accBatch;
  4. scheduler.batchSize = 100;
  5. String sch = '0 45 0/1 1/1 * ? *';
  6. System.schedule('Account Batch Process Scheduler', sch, scheduler);


Batch Class 2:
  1. ContactBatchProcess cntBatch = new ContactBatchProcess(); // Batch Class Name
  2. UniversalScheduler scheduler = new UniversalScheduler();
  3. scheduler.batchClass = cntBatch;
  4. scheduler.batchSize = 500;
  5. String sch = '0 45 0/1 1/1 * ? *';
  6. System.schedule('Contact Batch Process Scheduler', sch, scheduler);



What is aura:attribute in lightning components?

What is aura:attribute?
Attributes on components are like instance variables in objects. They’re a way to save values that change, and a way to name those value placeholders. 

Example:
Created Component called AttributeComponent:

  1. <aura:component >
  2.     <aura:attribute name="ProjectName" type="String" required="true"/>
  3.     <aura:attribute name="DefaultView" type="String" default="This is default String"/>
  4.     <aura:attribute name="AccountInfo" type="Account" />
  5.  
  6.     <lightning:card title="Grouped Item">
  7.         <p> Project Name: {!v.ProjectName}</p>
  8.         <p> Default Value: {!v.DefaultView}</p>
  9.         <p> Account Name: {!v.AccountInfo.Name}</p>
  10.         <p> Account Number: {!v.AccountInfo.AccountNumber}</p>
  11.     </lightning:card>
  12.    
  13. </aura:component>

I have created 3 attributes and displayed in the above example.
First Attribute called "ProjectName" and type "String" and required as true.
Second Attribute called "DefaultView" and type "String" with Default value.
Third Attribute called "AccountInfo" and type "Account" (Standard Object).

Created another Component called PassAttributeValue:

  1. <aura:component >
  2.     <c:AttributeComponent ProjectName="My Project" AccountInfo="{'sobjectType': 'Account', 'Name' : 'Test Account', 'AccountNumber' : '322342'}"/>
  3. </aura:component>

In this component, I am passing/assigning values to the attributes. So if I run PassAttributeValue component via lightning app, then output will be as below,



Attribute Data Types:
aura:attribute type supports the following data types,
  • Primitives data types, such as Boolean, Date, DateTime, Decimal, Double, Integer, Long, or String. The usual suspects in any programming language.
  • Standard and custom Salesforce objects, such as Account or MyCustomObject__c.
  • Collections, such as List, Map, and Set.
  • Custom Apex classes.
  • Framework-specific types, such as Aura.Component, or Aura.Component[]. These are more advanced than we’ll get to in this module, but you should know they exist.

Reference:

What is lightning:card in Salesforce?

Lightning:card tag (lightning component) is similar to apex:outputpanel (Visualforce page). It act as a container. 

A lightning:card is used to apply a stylized container around a grouping of information. The information could be a single item or a group of items such as a related list.

A lightning:card contains a title, body, and footer. To style the card body, use the Lightning Design System helper classes.

  1. <aura:component >
  2.     <lightning:card title="Container" iconName="standard:account">
  3.      This is for Testing.
  4.     </lightning:card>
  5. </aura:component>

title attribute is required to use lightning:card.
iconName You can set icon name from this link.

Reference:

Tuesday 27 February 2018

Is My Domain Required to Use Lightning Components in Salesforce?

Is My Domain Required to Use Lightning Components in Salesforce?

YES

Reason:

To use Lightning Components, your organization needs to have a custom domain configured using My Domain.

So what the heck is a custom domain, and why do you need to have one to use Lightning Components? First of all, a custom domain is a way to have your very own Salesforce server…sort of. It’s a way for you to use Salesforce from your own, customized URL, rather than a generic Salesforce instance URL. That is, once you have a custom domain, you’ll use Salesforce at https://yourDomain.my.salesforce.com/, which is reserved exclusively for your org’s use. Let other folks continue to use and share https://na30.salesforce.com/. Your custom domain puts you on your own private Internet island.

Setting up a custom domain has a lot of benefits besides just getting you a cool URL. Among other things, a custom domain lets you:
  • Highlight your business identity with your unique domain URL
  • Brand your login screen and customize right-frame content
  • Block or redirect page requests that don’t use the new domain name
  • Work in multiple Salesforce orgs at the same time
  • Set custom login policy to determine how users are authenticated
  • Let users log in using a social account, like Google and Facebook, from the login page
  • Allow users to log in once to access external services

Reference:
https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_prereqs

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...