Most Common Salesforce Apex Operations Part -2

by Rijwan Mohmmed

Hello friends, today we will discuss Most Common Salesforce Apex Operations Part -2. We all know there are many small-2 pieces of code in the apex that we need every time when we do code.

Also check this: Most Common Salesforce Apex Operations

Apex Operation :

1. How to get the First day of the month using apex in salesforce

Date dt = System.Today();
System.debug('##First Day ==> ' + dt.toStartOfMonth());

2. Remove spaces from a string using Apex in Salesforce

//remove white space from string
String str = 'Techdicer Keep Learning';

3. Validate Email address using Apex in Salesforce

String email = '';

Boolean validateEmail = Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}[.]{0,1}[a-zA-Z]{0,2}', email.trim());

System.debug('validateEmail===> ' + validateEmail);

4. Convert a Set of strings to a List of Strings

Set<String> stringSet = new Set<String>{'Techdicer', 'KeepLearning'};
List<String> stringList = new List<String>(stringSet);
//also you can use stringList.addAll(stringSet);
System.debug('stringList ==> ' + stringList);

5. Convert a List of strings to a Set of Strings

List<String> stringList = new List<String>{'Techdicer', 'KeepLearning', 'KeepLearning'};
Set<String> stringSet = new Set<String>(stringList);
//also you can use stringList.addAll(stringList);
System.debug('stringSet==> ' + stringSet);

6. Get Session Id In Apex Salesforce

String sessionId = UserInfo.getSessionId();
System.debug('sessionId==> ' + sessionId);

Reference :

  1. Salesforce Apex
What’s your Reaction?

You may also like

Leave a Comment