Activity Forums Salesforce® Discussions What is the role of Utility Methods in Salesforce ?

  • Deepak

    Member
    February 20, 2020 at 1:23 pm

    Hi KIrandeep,

    Utility methods perform common, re-used functions which are helpful for accomplishing routine programming tasks. Examples might include methods connecting to databases, performing string manipulations, sorting and searching of collections of data, writing/reading data to/from files etc.

  • Shweta

    Member
    February 20, 2020 at 1:36 pm

    Utility classes are helper classes that consist of reusable methods. This method is like you have any other apex class, where you have written some code and you can use those methods in Trigger.

    Example:

    trigger updateOpp on Opportunity (before insert){
     for(Opportunity  opp : Trigger.new){
     opp.formattedDate__c = TriggerHelper.formatDate(opp.someDate__c);
    }
    }
    
    //Utility Class
    Public Class TriggerHelper{
    Public Static string formatDate(Date inputDate){
       return inputDate.format();
    }
    }

     

     

  • Manish

    Member
    February 20, 2020 at 1:54 pm

    Utility Classes are helper classes that are reused for further use.

  • Marziya

    Member
    February 20, 2020 at 2:14 pm

    Utility Class, also known as Helper class, is a class, which contains just static methods, it is stateless and cannot be instantiated. It contains a bunch of related methods, so they can be reused across the application. As an example consider Apache StringUtils, CollectionUtils or java. lang.

Log In to reply.

Popular Salesforce Blogs