Friday, October 04, 2019

Checking Salesforce Classic or Salesforce LEX using javascript

Simple as this :

1
2
3
4
5
6
7
8
9
var isClassic ='false';

 console.log ('@@@ UIThemeDisplayed '+ '
{!$User.UIThemeDisplayed}');
 if('{!$User.UIThemeDisplayed}
' == 'Theme3')
{
   isClassic='true'; 
}

To use visualforce page within Salesforce LEX is to use this url . Some scenario that you might want to apply this is when you want to redirect to Visualforce page in Lightning.

1
/one/one.app#/alohaRedirect/apex/apexpagename?parameter

Friday, August 23, 2019

Method to retrieve correct ID from formula field.

One idea that really helpful to be delivered. Please vote
Reduce the compiled formula character cost of CASESAFEID()

Correct way to store ID in formula

Formula field only return 15 char ID and will be treated as String / Text . Which mean it will be treated as case insensitive in SOQL.

SELECT Id,Name,Parent.Id, Parent.Name, Ultimate_Parent_Account_ID1__c FROM Account WHERE Ultimate_Parent_Account_ID1__c ='001xxxxxxxxxQpK'

Will return record regardless the letter case
And also another  risk if  we query this with 18 digit ID as it will return 0 data.

As conclusion, normal formula with text return type is not able to capture the Salesforce Id correctly. 
In order to make it return as ID use CASESAFEID() . However this formula consumes so much character so that is the reason why you need to vote above idea.

Retrieve the correct Id from formula in Apex

If we are not able to use casesafeid in formula field , then we might need to be careful when retrieve record using formula field because SOQL is case-insensitve and ID is case sensitive. Honestly I wish that Salesforce provides a function that I can use directly in SOQL something like this ‘where casesafeid(Ultimate_Parent_Account_ID1__c) = ='001xxxxxxxxxQpKAAU' but unfortunately it is not available for this time being.

In order to ensure the Id is correct , we need to cast it to Id .Please note that I cast String to ID :
 Id ultimateid = (ID)account.Ultimate_Parent_Account_ID1__c . 

With this I can use the actual Id for further processing.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
String accountId15Char = '001xxxxxxxxxQpK';//because it will not entertain Id type or 18 character
Map<Id,Account> mapUltimateAccount =new Map<Id,Account>
                                      ([Select Id ,Parent.Id,Parent.Name  ,Ultimate_Parent_Account_ID1__c from Account where
                Ultimate_Parent_Account_ID1__c=:accountId15Char]);
        
         system.debug('@@@ mapUltimateAccount ' + mapUltimateAccount.size());
        //ultimate id contains complete hierarchy 
        //and exclude the account itself should be more than 1
        if(mapUltimateAccount.size()>1){
            for(Id accountId :mapUltimateAccount.keySet()){
               Account account =mapUltimateAccount.get(accountId);
               Id ultimateid = (ID)account.Ultimate_Parent_Account_ID1__c ;
               system.debug('Original Ultimate Id ' + account.Ultimate_Parent_Account_ID1__c+ ' , after convert to Id '+ ultimateid);
      
      //here you can have mechanism to compare id whether it returns the correct id
  
            }
           
        }

I think that's it for today. See you in next entry.