In my organisation , they ve written a class and in description it says " This is Utility Class " . Actually what is the purpose of utility class ? Why are we using that ?

  • 1
    if u go thru the class methods, variables, properties a few times, and search for where all its been used, you will definitely get a good idea on it purpose. even after that if you can't figure it out, you can share the class code to see if someone can help out May 13, 2015 at 5:40
  • 2
    This is part of your apex architecture, and the specific reasons for this class is something you'd better ask your architects or senior developers. In general: ususally relates to separation of concerns and maintainability of your code. May 13, 2015 at 12:53

3 Answers 3


The purpose of a utility class is to serve as a single one-stop-shop for reusable pieces of code. Basically any variable, method, inner class and whatever it might be that is used multiple times across multiple other classes within the project, can reside into a single (or multiple) utility class(es), which helps writing more elegant and structured code, as well as makes the code easier to maintain.


Utility classes are your friend. In addition to @Bachovski use cases, my Util methods provide centralized solutions for caching reference data to save on SOQL calls - especially when you have a complex environment wherein triggers fire on multiple objects per transaction. So, for example, sometimes you have code that needs to execute logic that varies based on running user's Profile name.

The Util class method getProfile(someName) will return the Profile object for a given name but cache all the Profiles on the first invocation of Util.getprofile(..) as the Profiles don't change in a given transaction but multiple triggers/handler classes may need the profile name for logic switching.

You'll find that as you move from org to org, that you'll copy over your Util methods and build on them -- within months/few years - you'll have a robust set of commonly-executed functionality that will save on time and make your calling logic cleaner and more consistent.


Utility class contains functions or methods which might be used frequently in a lot of class in the SFDC instance. eg. we want to get the label or API Name of any custom objects or to get the name of the record type from the id.

We write a generic method in the utility class which does the job for you and you can reuse the code of that class in any other class.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .