Activity › Forums › Salesforce® Discussions › What is Utility Method in Salesforce Apex?
Tagged: Field Value, Helper Class, Public Class, Salesforce Apex, Triggers in Salesforce, Utility Class, Utility Method
-
What is Utility Method in Salesforce Apex?
Posted by Aditya on February 20, 2020 at 6:23 AMWhat is Utility Method in Salesforce Apex?
Ratnesh replied 6 years, 2 months ago 3 Members · 2 Replies -
2 Replies
-
Hi Aditya,
Utility classes are just like helper classes that consist of reusable(when required many times ) methods.
From triggers, we can call methods in public classes. This helps to reduce code in the trigger and make it more organized.
If we have a trigger on the opportunity which does date format and assign it to a field value, it can be written as follows with the help of utility classtrigger 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(); } }-
This reply was modified 6 years, 2 months ago by
Deepak.
-
This reply was modified 6 years, 2 months ago by
Forcetalks.
-
This reply was modified 6 years, 2 months ago by
- [adinserter block='9']
-
Utility classes are helper classes that consist of reusable methods.
From triggers, we can call methods in such public classes.
-
This reply was modified 6 years, 2 months ago by
Forcetalks.
-
This reply was modified 6 years, 2 months ago by
Log In to reply.