Skip to content

Instantly share code, notes, and snippets.

@cynthiabellmcgillis
Last active November 3, 2018 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cynthiabellmcgillis/f9178c7bd2ba02ea1a611a531fdd15c0 to your computer and use it in GitHub Desktop.
Save cynthiabellmcgillis/f9178c7bd2ba02ea1a611a531fdd15c0 to your computer and use it in GitHub Desktop.
Second attempt, now with no switch statements!
trigger DateLogicOpp2 on OpportunityLineItem (before insert, before update) {
for (OpportunityLineItem oli :Trigger.new) {
if(oli.ServiceDate !=null){
DateTime startDate = DateTime.newInstance
(oli.ServiceDate, Time.newInstance(12,0,0,0));
if (oli.Materials_Due_2_Weeks__c) {
oli.Materials_Due_Date__c = oli.ServiceDate - (Integer.valueOf(startDate.format('u')) + 11);
} else {
oli.Materials_Due_Date__c = oli.ServiceDate - (Integer.valueOf(startDate.format('u')) + 4);
}
oli.Internal_Due_Date__c = oli.Materials_Due_Date__c.addDays(-2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment