Activity › Forums › Salesforce® Discussions › What is the role of Utility Methods in Salesforce ?
-
What is the role of Utility Methods in Salesforce ?
Posted by Kirandeep on February 20, 2020 at 11:25 AMWhat is the role of Utility Methods in Salesforce ?
Marziya replied 6 years, 3 months ago 5 Members · 4 Replies -
4 Replies
-
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.
- [adinserter block='9']
-
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(); } } -
Utility Classes are helper classes that are reused for further use.
-
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.