You need to sign in to do that
Don't have an account?
JaredPH
Help? Trigger okay except when null value in field
I've gotten some help and worked out a trigger. It does what I want with updating a field based on a comparison of a date ("accepted__c") and datetime field ("payment_ref__c"). I just realized that it gives an error if one of the comparison date or date/time fields is blank. Is there an easy way to insert a line so it skips everything if either of those fields are blank? Also, am I going to run into trouble if I use an opportunity record type that doesn't include one of the fields referenced in the trigger?
Thanks for any help you can give!!
Here is the trigger:
Trigger LateApp on opportunity(before update)
{
datetime accdt;
date payref;
list<opportunity> opp=new list<opportunity>();
for(opportunity o : trigger.new)
{
accdt=trigger.new[0].Accepted__c.date();
payref=trigger.new[0].Payment_ref__c.adddays(45);
if(payref.daysBetween(accdt.date()) >= 0 && payref.daysBetween(accdt.date()) < 30)
{
o.Late_App__c ='Late1';
}
if(payref.daysBetween(accdt.date()) >= 30 && payref.daysBetween(accdt.date()) < 60)
{
o.Late_App__c ='Late2';
}
if(payref.daysBetween(accdt.date()) >=60)
{
o.Late_App__c ='Late3';
}
if(payref.daysbetween(accdt.date()) <-15)
{
o.Late_App__c='';
}
opp.add(o);
}
}
Hi,
You will just need to have an outer if condition that checks for nulls in the two date fields.
Also, I noticed that your trigger was incompletely built to handle bulk requests.
Below is the code with the change requested and my fix to handle bulk data.
All Answers
Hi,
You will just need to have an outer if condition that checks for nulls in the two date fields.
Also, I noticed that your trigger was incompletely built to handle bulk requests.
Below is the code with the change requested and my fix to handle bulk data.
Perfect! Thanks for your help.