
I have a date field named:
Project_Start_Date__c
I have a bunch of Date fields that get filled when the Project Start Date is entered. I used workflow rules to update these fields.
This is the workflow rule I used:
AND( OR( ISNEW(), ISCHANGED( Project_Start_Date__c ) ), NOT(ISBLANK( Project_Start_Date__c)) )
and then did field updates:
using a formula like this on the Date(s) field(s):
Project_Start_Date__c + 77 +
CASE(MOD(
Project_Start_Date__c - DATE( 1900, 1, 1 ), 7 )
,0,FLOOR(77/5)*2
,1,FLOOR((77+1)/5)*2
,2,FLOOR((77+2)/5)*2
,3,FLOOR((77+3)/5)*2
,4,FLOOR((77+4)/5)*2
,null)
I have a new requirement now - where I have to Auto populate the dates - based on Project Start Date and a checkbox named 'Dynamic Dates TB'
When the User checks the 'Dynamic Dates' checkbox - changing the end date or start date for any of the tasks should change the SUBSEQUENT dates:
Eg: If Kickoff Call with Client End Date is changed to 9/13 then all dates subsequent to it should change accordingly.
I wrote the following trigger. Here is what is happening:
1.The Kickoff Call End Date gets updated
2. The Data Req Form Start Date gets update.
But here are the problems:
1. If I change the Kickoff Call End Date the The Data Req Form Start date is not accordingly getting updated
2. Also, if I change the Kickoff Call End Date to another date, say 10/2 and click save - it doesn't get saved and ends up displaying 9/12.
Can someone please help. I am brand new to coding and am working on a tight deadline.
trigger TBAutoClientInitiation 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;
if(StartDate != null )
{
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(o.Dynamic_Dates_TB__c==True)
{
o.TB_Kickoff_Call_w_Client_ED__c = AddBusinessDays(o.TB_Kickoff_Call_w_Client_SD__c,1);
o.Data_Req_Start_Date__c = AddBusinessDays( o.TB_Kickoff_Call_w_Client_ED__c,18);
}
}
}
}
5 answers
This community is focused on design and configurations issues!
Please post this to Developer Community and stackexchange for quick response.
https://developer.salesforce.com/forums
http://salesforce.stackexchange.com