• naman gupta 33
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Create a VisualForce page using standardController="Project__c" to display:
  • The Name, Start Date, End Date and Customer fields in a single row at the top of the screen
  • Add a button to the standard Project screen (the one automatically generated by Salesforce) to open this custom screen.
  • This is just to practice the use of VisualForce and does not need to have any other functionality on it.
I need to generate a project task list with due dates for each task  The due dates are calcualted b taking the total # of days for the project and dividing by the number of tasks, so for a 90 day project with 3 tasks, each task would be 30 days apart, with teh first occuring 30 days after the project start date.  The follwing code gives me the tasks, but each task has the same due date -Start_date +30 days.  So I have something wrong in the For loop, but cna't figure out what it is.  Can someone help?

trigger tasks on Project__c (after insert)

{List<Task> newTasks = new List<Task>();

for (Project__c proj : Trigger.New) {
    Date DueDate = proj.Start_Date__c+30;
    Date nextDueDate = DueDate;
    
    for (Integer i = 0; i < proj.Number_of_Tasks__c; i++) 
    
    {
        Integer taskDur = integer.valueOf(proj.Task_Duration__c*(i+1));
        nextDueDate = DueDate.addDays(taskDur);

        newTasks.add(new Task(
            Subject ='Project Task - '+ (i+1),  
            Status = 'In progress',
            Priority = 'High',
            ActivityDate =  nextDueDate,
            WhatId = proj.id
        ));
    }

    //proj.Number_Of_Tasks__c = 0;


insert newTasks;

}
}