Learn & Practice Set Methods in Salesforce

Divya Agarwal
JanBask Training
Published in
4 min readApr 11, 2022
Image Credit- JanBask Training

In today’s world, there are various applications related to data grouping that uses salesforce methods. Salesforce comprises various set methods that are responsible for wide application utilities. The list methods are emphasized in the apex because the SOQL Query is a list.

This article is meant to enlighten you about salesforce and the different methods that are used in it. Read the article up to the end to know more about the salesforce and different set methods in salesforce.

What is set in Salesforce?

A set of salesforce could be an assortment of varieties of knowledge in an orderly manner. These knowledge sorts are often primitive knowledge sorts, user-defined knowledge sorts, constitutional apex knowledge sorts, etc. set components dynamically develop and grow throughout the runtime by resembling a list.

If you would like to form implications of a group you ought to strive for the victimization of the set of keywords. You can use it to set the strategies at any time. All in all, a group is an associate degree ordered combination of various information and varieties that comprises the various counts and numbers of a certain order of the records or datasets. It is the random combination of many elements where there is no replica of any other element arranged accordingly as per the specific kind of sequence.

What are the different types of set methods in salesforce?

Set strategies comprise a collection category that is liable for the gathering of distinctive parts wherever there is no permission or duplication of the values of the objects. The main application of set strategies in salesforce lies within the undeniable fact that they worked on the premise which is being initialized with the set keyboard.

As we tend to understand that the set parts will have possession of random or reasonable information sorts which may be used as an outline or constitutional. Set strategies are also regarded as once instance strategies that guide America in favor of operational methodology. We require a collection creator and set methodology for implementing the set of various information varieties.

Some of the types of set methods in salesforce are as follows:

  • add(set element): used for the insertion of an element. This returns a boolean type value; true if the original set modifies as a result of the call.
  • add(index,setElement): used when new elements are to be added at specific index.
  • addAll(from the list): used for insertion of a list of elements only after cross-checking their absence. It returns a boolean value, true if the original set modifies due to the call.
  • addAll(SetElement): Inserts a particular set of elements only after calling a distinct method.
  • clear(): used to remove the element in a specified set. Its return type is void.
  • clone(): used for the duplication or copy of an element in the set. It returns the set of the same type after duplication.
  • remove(setElement): Removes particular element from the set if its present.
  • size(): This counts the number of elements in totality.
  • equals(set2): used to compare two sets and thus return the output in boolean that is true or false.
  • hashCode(): Returns the hash-code corresponding to a particular set.
  • removeAll(setOfElementsToRemove): Removes the elements which are already present in the original set.
  • containsAll(listToCompare): Returns a true value if the list of the set contains all the values of required elements of a particular list set. It also returns a boolean value true if the set contains all the specified elements of the particular list.
  • toString(): This returns the string description of the set. Its return type is String.
  • contains(setElement): This returns a boolean value true if the set contains the specified element.
  • retainAll(setOfElementsToRetain): It returns the boolean value, true if and only if the originality of the set has been modified as the call result.

What exactly is a method and what elaborates its creation in salesforce?

Let’s discuss what are the set methods in salesforce in apex:

The set in apex is outlined because of the assortment of many statements that shares some common characteristics and behavior thus they will be classified along the and will perform specific operation supported by a question. We should grasp that technique consist of many elements that embody the header and especially the techniques that consist of the condition for testing.

By following the texts given below we can create the method in the apex set class:

Modifiers: it is associated with nonobligatory service which will tend to guide the compiler. it is often accountable for shaping the access sort of strategies.

Return type: as the name suggests it is a technique that is most likely a break and should come back, is used underneath the strategies in the return value type.

Technique name: literal name of the strategies that display the parameter list being established within the sort of technique signature.

Technique body: it has many numbers of statements being outlined concerning precise technique and also the practicality of the strategy.

Parameters: it is treated a bit like a placeholder within which a price is passed because the methodology is invoked. The list of parameters defines the kind the order and therefore the total variety of outlined parameters in an exceedingly specific methodology.

Conclusion

We hope that this article was of relevance to your doubts regarding salesforce. Through this article, we tried to give you the most relevant information about the salesforce and set methods in salesforce.

If you are an aspiring candidate for salesforce exams or if you are preparing for a professional career in salesforce, the knowledge of set methods in salesforce is of great importance for you. We hope you liked reading this article.

--

--