function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
marcobmarcob 

put code in trigger, class or ???

Hi,

 

i have a piece of business logic, but don't know where to put it. It concerns the recalculation of leave entitlements.

 

If i put it in a trigger, it won't be available for me to use in a screen. For instance if i want to create a button 'recalculate leave entitlements' on a Visual Force page.

 

It seems to me that i have to put it in a separate class. This way i can call it from a trigger, and also from a Visual Force page (via the controller/extension).

 

But i also want to make sure leave entitlements are recalculated whenever i import data from for instance an Excel sheet.

 

What is my best option here?

 

Please advice.

 

Many thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
TheIntegratorTheIntegrator

if you use import function inside salesforce, you get an option to execute trigger on import, if you will call this function from the trigger, each record you import from excel sheet will also hit the trigger by selecting this option with import.

All Answers

TheIntegratorTheIntegrator

Create a separate public class with this function, you can then call it either in VF page or in trigger.

marcobmarcob

But how can i use this code when i import data from an Excel sheet then?

TheIntegratorTheIntegrator

if you use import function inside salesforce, you get an option to execute trigger on import, if you will call this function from the trigger, each record you import from excel sheet will also hit the trigger by selecting this option with import.

This was selected as the best answer
marcobmarcob

ok, that's what i needed to know.

Thanks a lot!

br, Marco

TheIntegratorTheIntegrator

No problem, just a minor correction, the checkbox in import is for workflows not triggers. Triggers are by default fired on import.