rnew icon6Grab Deal : Flat 30% off on live classes + 2 free self-paced courses! - SCHEDULE CALL rnew icon7

sddsfsf

Methods In Salesforce Introduction To Methods In Apex

 

Salesforce, Inc. is a cloud computing and SaaS provider. In general, Method can be defined as a programming approach which is declared as a component of the class, which may include objects of the class if any or a simple way to define a method is a procedure that is made up of several statements that work together to complete an operation. In Apex methods are the same as the general methods.

A method generally consists of Modifiers, Return Type, Method Name, Parameters, and a Method body. Now let us see in detail about the Methods in Salesforce.

Types of Methods in Apex

Numerous Methods in Salesforce can be applied to organise data depending on various data types. 

The following are the Methods in Salesforce for collections:-

Set

Set methods are part of a set class, which is responsible for collecting unique items when copying object values are not allowed. In Salesforce, set methods are most useful because they operate on sets, which are ordered groups of items created using the Set keypad. Salesforce Integration Cloud offers an individual view of customer data for huge businesses and organizations. It helps users connect huge amounts of data scattered across different cloud platforms. Sign up for an industry-oriented Salesforce developer training program to provide you with more advanced exposure in the field of Salesforce.

We all know that the elements of a set may either have a specified or a built-in data type, or they can have a data type that is completely arbitrary. One of the most well-known types of methods is the instance method, but there is another kind of method that points us in the direction of performing an operation on a specific method: set methods. For the various sets of data, we also need a set Constructor and set method. Set methods are part of a set class, which is in charge of collecting unique items whose object values cannot be duplicated. As the name implies, set procedures in Salesforce rely on sets, which are ordered groups of items that may be established using the Set keyboard shortcut. Take your cloud computing awareness to another level with cloud computing courses.

Set Methods

1. Add (Set Element)

It is used for the insertion of an element into the set.

2. Add All (From List)

It is used for the process of adding together the whole list of components that make up a certain set. After invoking a specific method and then verifying that the items being added do not appear elsewhere on the list of sets, it is possible to proceed with the adding procedure.

3. Add All (FromSet)

It is useful for adding all of the components that are included in a given setlist. When these components are not already included in the set's element list, this step is taken to accommodate them.

4. Clear ()

It is useful in the process of removing all of the items in the set that has been defined. clear() methods have a syntax that looks like this: public void clear (). The value that is returned has a type of "void."

5. Clone ()

It is useful in the process of making a replica of the set that may be used more than once. The syntax looks like this: public set object clone () The type of the value that is returned by the set method is Set (of the same type).

6. Contains (Set Element)
7. Contains All (List To Compare)

It is helpful in returning the true value in case of the list of set if containing all the required elements of a particular set list.

8. Contains All (Set To Compare)

It is helpful in returning the true value in case of the set if containing all the due number of elements of a particular set.

  • The syntax is public Boolean contains (Object setElement)
  • The return value from the set method is type- Object.
  • The data type for the return value is – Boolean.
9. Equals (Set2)
10. HashCode ()
11. IsEmpty ()
12. Remove (Set Element)
13. Remove All (List of ElementsTo Remove)

It is helpful in removing or deleting the elements which are present in a specific list of set if there are already present inside the original set list.

14. RemoveAll (set of Elements To Remove)

It is helpful in removing or deleting the elements which are present in a specific set if there are already present inside the original set.

15. RetainAll (List of Elements To Retain)
16. RetainAll (Set of Elements To Retain)
17. Size ()
18. To String ()

List

To put it simply, an index is used to uniquely identify each item in a list. Any basic type, collection, sObject, custom type, or built-in Apex type may be used for a list's element.

It is possible to stack lists inside one another to create multidimensional lists that may contain any collection. An array of arrays is one way to organise a collection of Integers, for instance. There may be a maximum of five layers of nesting inside a list, with each level containing one more collection.

The List keyword and the type of the data to be stored in the list (primitive data, sObject, nested list, map, or set) enclosed in > characters constitute a valid list declaration.

// Make an empty list of String
List my _list = new list();
// Create a nested list
List>> my_list_2 = new List>>();
To access elements in a list, use the List methods provided by Apex. For example:
List myList = new List();
myList.add(47);               
Integer i = myList.get(0);          
myList.set(0, 1);
myList.clear(); 

List Methods

1. Add (List Element)

To add an element

2. Add (Index, List Element)

Inserts an element into the list at the specified index position.

3. Add All (From List)

Adds each of the items that are included in the set or list that has been supplied to the list that is calling the method. It is required that both lists have the same structure.

4. Add All (From Set)

Adds each of the items that are included in the set or list that has been supplied to the list that is calling the method. It is required that both lists have the same structure.

5. Clear ()

Prepare the beginning of the list. Brings the size of the list down to zero.

6. Clone ()

Makes a duplicate copy of a list

7. Contains (List Element)
8. DeepClone (PreserveId, Preserve Readonly Timestamps, PreserveAutonumber)
9. Equals (List 2)

Performs a comparison of the lists and returns true if they are identical. This anticipates that the order will be consistent throughout all of the listings.

10. Get (Index)

Returns the list element for a specified index.

11. Gets Object Type ()
12. Hash Code ()
13. Index of (List Element)
14. IsEmpty ()

To check if list is empty or not. Returns true if list is empty

15. Iterator ()
16. Remove (Index)

Removes list element at a specified index

17. Set (Index,List Element)

Replace a list element at a specified index.

18. Size ()

Returns the number of elements in a list.

19. Sort ()

Sorts the items in a list

20. ToString ()

Map

A map is a collection of classes, each of which is made up of a collection of components. It is a combination of a key and a value. Each and every one of the map's elements has both a key and a value associated with it. The key has to be one of a kind, but the value may be repeated. It allows for memory to be allocated dynamically. It's kind of like a collection of key-value pairs, except that each key (which is unique) only maps to one value. Both the keys and values may be any form of data.

Creating a Map:

Map variablename=new Map();
In salesforce, we have standard object Account, If we want to map id with account, it is represented as,
Map Accmap=new Map();
Example:-
Map mapname=new Map();
mapname.put(‘Green’,’trouser’);
mapname.put(‘blue’,’pants’);
mapname.put(‘black’,’ trouser’);
When the above is executed with both mapname.keyset() and mapname.values() method we will get the values as for keyset:{green, blue, black}
for values:{ trouser, pant, trouser }.

From this, we can see that values can be duplicated.

If we try to duplicate key, it overrides the existing key and gives the output with the key that is given at last.

Map Methods

1. Clear ()
2. Clone ()
3. Contains Key (key)
4. Deep Clone ()
5. Equals (Map2)
6. Get (key)
7. Get sObjectType ()
8. Hash Code ()
9. Is Empty ()
10. KeySet ()
11. Put (Key,Value)
12. Put All (From Map)
13. Put All (sobject Array)
14. Remove (key)
15. Size ()
16. To String ()
17. Values () 

Difference Between List, Set and Map in Salesforce

List:

  • A list is a collection of items, such as user-defined objects, basic data types (String, Integer, Date, etc.), sObjects, Apex objects, or other collections (can be multidimensional up to 5 levels).
  • There is room for duplicates in the list.
  • The position on the list index begins with zero.

Set:

  • Set is a collection of distinct, unordered items. 
  • Either basic data types, such as strings, integers, and dates, or sObjects may be stored in it.
  •  Set permits unique values.

Map:

  • The key-value pair collection that makes up a map.
  • When it comes to values, keys may be any basic data type (String, Integer, Date, etc.), whereas values can be any primitive data type, as well as Apex objects, sObjects, or other collections.
  • Map permits duplicate values, but every key must be distinct from the others.

String

String Class Salesforce is essentially a class variable that is comprised of a variety of Apex String Methods, and it is through the use of these specific String methods that Alt-text users are granted the ability to carry out varied activities using a variety of strings. Therefore, a string class is produced in Salesforce whenever these String Methods are used with one another.

String Methods

The String is a collection of characters that does not have any restrictions placed on it. Within Salesforce, there are a number of different techniques for String.

1. ToLowerCase() Converts all characters in the String to lowercase using the default (English US) locale rules

2. ToUpperCase() Converts all of the characters in the String to uppercase using the rules of the default (English US) locale.

3. Capitalize() Returns the current String with the first letter changed to title case.

4. Contains(substring) Returns true if and only if the String that called the method contains the specified sequence of characters in substring.

5. ContainsIgnoreCase (substring) Returns true if the current String contains any of the characters in the specified String; otherwise, returns false

6. ContainsAny(inputString) Returns true if the current String contains any of the characters in the specified String; otherwise, returns false

7. ContainsNone(inputString) Returns true if the current String doesn’t contain any of the characters in the specified String; otherwise, returns false.

8. ContainsOnly(inputString) Returns true if the current String contains characters only from the specified sequence of characters and not any other characters; otherwise, returns false.

9. StartsWith(prefix) Returns true if the String that called the method begins with the specified prefix.

10. StartsWithIgnoreCase (prefix) Returns true if the current String begins with the specified prefix regardless of the prefix case.

11. E ndsWith(suffix) Returns true if the String that called the method ends with the specified suffix.

12. EndsWithIgnoreCase (suffix) Returns true if the String that called the method ends with the specified suffix.

13. Substring(startIndex) Returns a new String that begins with the character at the specified zero-based startIndex and extends to the end of the String.

14. Substring (startIndex, endIndex) Returns a new String that begins with the character at the specified zero-based startIndex and extends to the character at endIndex - 1.

15. SubstringAfter(separator) Returns the substring that occurs after the first occurrence of the specified separator.

16. SubstringBefore(separator) Returns the substring that occurs before the first occurrence of the specified separator.

17. Trim() Returns a copy of the string that no longer contains any leading or trailing white space characters

18. Equals(stringOrId) This function will return the value true if the object that was handed in is not null and it represents the same binary sequence of characters as the string that is currently being accessed. You may compare a string to an object that represents a string or an ID by using this method.

19. EqualsIgnoreCase (secondString) This function will return true if the object that was handed in is not null and it represents the same binary sequence of characters as the string that is currently being used. Comparing a string to an object that represents a string or an ID may be done with the help of this method.

20. SwapCase() Performs a case change on every character and then returns the String that has been created in the default locale (English, United States).

Conclusion

As we can see there are numerous Methods in Salesforce corresponding to various data types. In which each performs a unique operation. Methods can be of two types pre-defined and user-defined. Pre-defined, as the name itself says that these are already defined and cannot be modified but whereas user defined methods are the methods declared by the users corresponding to their requirement. So one must know how and where to use these methods in order to gain maximum production. 

cta11 icon

Salesforce Course Training

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Trending Courses

Cyber Security icon

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models
Cyber Security icon1

Upcoming Class

16 days 05 Jul 2024

QA icon

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing
QA icon1

Upcoming Class

8 days 27 Jun 2024

Salesforce icon

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL
Salesforce icon1

Upcoming Class

7 days 26 Jun 2024

Business Analyst icon

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum
Business Analyst icon1

Upcoming Class

2 days 21 Jun 2024

MS SQL Server icon

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design
MS SQL Server icon1

Upcoming Class

9 days 28 Jun 2024

Data Science icon

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning
Data Science icon1

Upcoming Class

2 days 21 Jun 2024

DevOps icon

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing
DevOps icon1

Upcoming Class

5 days 24 Jun 2024

Hadoop icon

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation
Hadoop icon1

Upcoming Class

2 days 21 Jun 2024

Python icon

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation
Python icon1

Upcoming Class

17 days 06 Jul 2024

Artificial Intelligence icon

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks
Artificial Intelligence icon1

Upcoming Class

10 days 29 Jun 2024

Machine Learning icon

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning
Machine Learning icon1

Upcoming Class

23 days 12 Jul 2024

 Tableau icon

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop
 Tableau icon1

Upcoming Class

2 days 21 Jun 2024