You need to sign in to do that
Don't have an account?
Caisa
Null Pointer Expection
Can someone please help solve this NullPointer Exception:
Error:Apex trigger TruBidCompletion caused an unexpected exception, contact your administrator: TruBidCompletion: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TruBidCompletion: line 31, column 1
trigger TruBidCompletion on Opportunity (before update)
{
public static Boolean IsWeekendDay(Date dateParam)
{
boolean result = false;
system.debug('dateParam = '+dateParam);
//Recover the day of the week
Date startOfWeek = dateParam.toStartOfWeek();
system.debug('startOfWeek = '+startOfWeek);
Integer dayOfWeek = dateParam.day() - startOfWeek.day();
system.debug('dayOfWeek = '+dayOfWeek);
result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
system.debug('result = '+result);
return result;
}
public static Date AddBusinessDays(Date StartDate, integer BusinessDaysToAdd )
{
//Add or decrease in BusinessDaysToAdd days
Date finalDate = StartDate;
system.debug('finaldate = '+finalDate);
integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
system.debug('direction = '+direction);
while(BusinessDaysToAdd != 0)
{
finalDate = finalDate.AddDays(direction);
system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);
system.debug('finaldate = '+finalDate);
if (!isWeekendDay(finalDate))
{
BusinessDaysToAdd -= direction;
}
}
return finalDate;
}
{
for(Opportunity o : Trigger.new)
{
/* If the user selects Round 1 as the Number of TruBid Rounds */
if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
{
/* Call the AddBusinessDays method called above to add 'x' days */
o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
}
Error:Apex trigger TruBidCompletion caused an unexpected exception, contact your administrator: TruBidCompletion: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TruBidCompletion: line 31, column 1
trigger TruBidCompletion on Opportunity (before update)
{
public static Boolean IsWeekendDay(Date dateParam)
{
boolean result = false;
system.debug('dateParam = '+dateParam);
//Recover the day of the week
Date startOfWeek = dateParam.toStartOfWeek();
system.debug('startOfWeek = '+startOfWeek);
Integer dayOfWeek = dateParam.day() - startOfWeek.day();
system.debug('dayOfWeek = '+dayOfWeek);
result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
system.debug('result = '+result);
return result;
}
public static Date AddBusinessDays(Date StartDate, integer BusinessDaysToAdd )
{
//Add or decrease in BusinessDaysToAdd days
Date finalDate = StartDate;
system.debug('finaldate = '+finalDate);
integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
system.debug('direction = '+direction);
while(BusinessDaysToAdd != 0)
{
finalDate = finalDate.AddDays(direction);
system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);
system.debug('finaldate = '+finalDate);
if (!isWeekendDay(finalDate))
{
BusinessDaysToAdd -= direction;
}
}
return finalDate;
}
{
for(Opportunity o : Trigger.new)
{
/* If the user selects Round 1 as the Number of TruBid Rounds */
if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
{
/* Call the AddBusinessDays method called above to add 'x' days */
o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
}
Try to update your "AddBusinessDays" method as below
All Answers
Try to update your "AddBusinessDays" method as below