Friday, February 28, 2020

Difference between UserInfo.getUiTheme() and UserInfo.getUiThemeDisplayed() in Salesforce

Salesforce currently supports the below themes
Theme1—Obsolete Salesforce theme
Theme2—Salesforce Classic 2005 user interface theme
Theme3—Salesforce Classic 2010 user interface theme
Theme4d—Modern “Lightning Experience” Salesforce theme
Theme4t—Salesforce mobile app theme
Theme4u—Lightning Console theme
PortalDefault—Salesforce Customer Portal theme
Webstore—Salesforce AppExchange theme

UserInfo.getUiTheme()
This method returns the preferred theme for the current user.

UserInfo.getUiThemeDisplayed()
Use getUiThemeDisplayed to determine the theme actually displayed to the current user.

Wednesday, February 19, 2020

How to validate Email address using apex in salesforce

Sample Code

String strEmail = 'test@test.com';
Boolean bValidateEmail = Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}[.]{0,1}[a-zA-Z]{0,2}', strEmail.trim());
System.debug('bValidateEmail ===> '+bValidateEmail);

Output

Friday, February 14, 2020

How to access the child records from sObject using apex in Salesforce

Sometimes we run the dynamic query based on different inputs at the time we store the data in sObject or list<sObject>
from that data sometimes we have to get the child records info, to get the child records info use the
getSobject('<relationshipName>') or getSobjects('relationshipname')

Note
 custom object relationships you would use the something similar to
sObj.getSObject('Your_Custom_Object__r')

Sample Code
sObject sObj = [SELECT Id, Name, Account.Name, Account.Owner.Name FROM Contact WHERE Id = '003B000000FgA2JIAV'];

String strContactName = (String)sObj.get('Name');
String strAccName = (String)sObj.getSobject('Account').get('Name');
String strAccOwnerName = (String)sObj.getSobject('Account').getSobject('Owner').get('Name');

System.debug('Contact Name ====> '+strContactName);
System.debug('Account Name ====> '+strAccName);
System.debug('Account Owner Name ====> '+strAccOwnerName);

Output