1

I'm trying to put (-60) value in the reminder time. it works but it is hard coded. I want it from custom settings so admins could edit the numbers from the GUI.

trigger setReminderEvent on Event (before insert){
    If(trigger.new[0].StartDateTime != null){
        trigger.new[0].IsReminderSet = TRUE;
        trigger.new[0].ReminderDateTime = trigger.new[0].StartDateTime.addMinutes(-60); 
        //CUSTOM SETTINGS INSTEAD-converted to datetime 
    }
}

someone please show me the right way for this. I can't use Integer or String for the .addMinutes(), only DateTime, How do i covert a text/numbers field from custom settings into DateTime in the trigger? I cant make the custom settings field DateTime because I could not tell it to be 'minus 60 minutes'.

better way or approach ?

1 Answer 1

3

Implement a Hierarchy Custom Setting and use an Number field. Example code might look like:

Integer offset = MyHierarchSetting__c.getOrgDefaults().Event_Reminder_Offset__c;
record.ReminderDateTime = record.StartDateTime.addMinutes(offset);

Please note you should get your trigger logic into a separate Apex Class, and act on all records, not just the first.

1
  • this does not work because .addMinute() is looking for datetime type, and was getting Integer type.
    – Ran Algov
    Dec 16, 2018 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .