What is Apex String Class in the Salesforce
Salesforce CRM helps thousands of companies around the world discover new opportunities, drive marketing campaigns, manage and use customer data, and improve communication (internal and external). Ultimately, it helps them improve their decision-making skills and fuel stronger business growth. In Salesforce there is an important concept which deals with many predefined methods to make the work easier in Salesforce. This is known as Apex String Methods.
String as we all know means string data type which deals with a set of characters with no specified limit.
- What is Apex?
- What is Apex String Class Salesforce?
- List of Apex String Methods Salesforce
- What are access modifiers in Salesforce?
Watch the video and learn all about Salesforce
What is Apex?
Apex is a proprietary language developed by Salesforce.com. Formally defined, Apex is a strongly typed, object-oriented programming language that enables developers to combine Force.com and API calls to execute transactions and stream instructions on the Force.com platform server.
It has a Java-like syntax, and its behavior is similar to a stored procedure in a database. It allows developers to add business logic to most system events, including button clicks, link record updates, and Visualforce pages.
Apex has a performance edition, unlimited edition, enterprise edition, and developer edition.
Let’s understand what is Apex used for:
Apex includes an application programming interface (API) that developers can use to access user data on Salesforce.com. This API enables developers to use common SaaS components such as web widgets or a multi-user database without having to traditionally develop much of the infrastructure.
Get to know more about Salesforce Data Type from our blog- Salesforce Data Types and Field Types.
What is Apex String Class Salesforce?
String Class Salesforce is basically a class variable that consists of various Apex String Methods and these particular String methods Salesforce allows Alt-textusers to perform multiple operations in different strings. So when these String Methods combine together they make a string class in Salesforce.
List of Apex String Methods Salesforce-
There are different types of Apex String Methods in Apex String Class that allow the users to deal with various pre-defined methods. These pre-defined methods are apex string methods Salesforce.
Some of the popular Apex String Methods are listed below-
- contains – The contains method will return the value True if the given string is present in the substring. Example –
String myProduct1 = ‘Salesforce'; String myProduct2 = 'Intllipaat Salesfoce Course'; Boolean result = myProductName2.contains(myProduct1); System.debug('Output will be true as it contains the String and Output is:'+result);
- charAt(index) – The charAt method allows the return of the value of the character specified in the particular index. Example-
String str = 'Hello Intellipaat.'; System.assertEquals(937, str.charAt(0));
- equals – The equals method allows returning true value if the given string and the string passed in the method have the same binary sequence of characters.
Note– The values must not be NULL, also, it is case sensitive.
String string1 = 'Intellipaat'; String string2 = 'Intellipaat'; Boolean result = string2.equals(string1); System.debug('Value of Result will be true as they are same and Result is:'+result);
- equalsIgnoreCase – This method will return true if stringtoCompare has the same sequence of characters as the given string.
Note– this method is not case-sensitive.
String string1 = 'intellipaat'; String string2 = 'INTELLIPAAT'; Boolean result = myString1.equalsIgnoreCase(string2); System.assertEquals(result, true);
- remove – This method deletes the string specified by stringToRemove from the specified string. This is useful when you want to delete certain characters from a string and you don’t know the exact index of the character to be deleted.
Note- This method is case-sensitive. If the same string appears but the case is different, this method will not work as a string method in Salesforce
String s1 = 'Salesforce and force.com'; String s2 = s1.remove('force'); System.assertEquals( 'Sales and .com', s2);
- indexOf – Returns the index of the first occurrence of the specified substring. If the substring does not occur, this method returns -1. Example-
String myString1 = 'abcde'; String myString2 = 'cd'; Integer result = myString1.indexOf(mystring2); System.assertEquals(2, result);
- startsWith – This method will return true if the given string starts with the prefix provided in the method.
Note- Method is not case sensitive.
String s1 = 'Salesforce and Intellipaat'; System.assert(s1.startsWith('Salesforce'));
- isAllUpperCase() – This string method will return True if the string contains all characters in uppercase.
//Return true String s1 = 'INTELLIPAAT'; Boolean b1 = s1.isAllUpperCase()
- isAllLowerCase()- This string method will return True if the string contains all characters in lowercase.
//Return true String s1 = 'intellipaat'; Boolean b1 = s1.isAllLowerCase()
Check out our blog on Salesforce Admin Interview Questions and Answers and ace your interview in your job interview.
What are access modifiers in Salesforce?
There are various access modifiers in Salesforce which provide data security and maintain data integrity in an enterprise. The access modifiers provide different access to different people according to their job roles. The access specifiers in Salesforce are-
- Private- This is the default, associate degreed means the tactic or variable is accessible solely at intervals in the apex string class category within which it’s defined. If you do not specify an access modifier, the method or variable is private automatically.
- Protected- This means that the variable is visible to any inner categories within the specified Apex class, and to the classes that stretch the defining Apex String class in Salesforce. You’ll be able to solely use this access modifier, let’s say ways and member variables. Note that it’s strictly more permissive than the default (private) setting, a bit like Java.
- Global- This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application.
- Public- This means the method or variable can be used by any Apex in this application or namespace. In Apex, if you want to make something public like it is in Java, you need to use the global access modifier.
Example of public and private access specifiers in Salesforce
// private variable s1 private string s1 = '1'; // public method sales() public string sales() { ... }
Get your queries cleared on Intellipaat’s Salesforce community!
The post What is Apex String Class in the Salesforce appeared first on Intellipaat Blog.
Blog: Intellipaat - Blog
Leave a Comment
You must be logged in to post a comment.