Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RecipeClass {
- public static void handleBeforeInsertUpdate (List<Recipe__c> newRecipes) {
- //use Active_Time_Units__c and Active_Time__c fields as the source and write the result to Duration__c
- //no list or set needs to be declared up here b/c you don't have a DML to declare
- //pass in the trigger.new records to the for loop, note that newRecipes in the List declared at the top is the same as newRecipes in the for loop
- for(Recipe__c newRecipe: newRecipes) {
- if(newRecipe.Active_Time__c <= 30 && newRecipe.Active_Time_Units__c == 'Minutes'){
- newRecipe.Duration__c = 'Quick';
- }
- if((newRecipe.Active_Time__c > 30 && newRecipe.Active_Time__c <= 60 && newRecipe.Active_Time_Units__c == 'Minutes') ||
- (newRecipe.Active_Time__c == 1 && newRecipe.Active_Time_Units__c == 'Hours')){
- newRecipe.Duration__c = 'Medium';
- }
- if((newRecipe.Active_Time__c > 60 && newRecipe.Active_Time_Units__c == 'Minutes') ||
- (newRecipe.Active_Time__c > 1 && newRecipe.Active_Time_Units__c == 'Hours')){
- newRecipe.Duration__c = 'Long';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement