0% found this document useful (0 votes)
2 views2 pages

Apex Trigger Code

The document contains two Salesforce Apex triggers for managing project statuses and task creation. The first trigger updates the status of a project based on its start and end dates, while the second trigger creates tasks linked to project milestones after a project is inserted or updated. Both triggers ensure that project statuses are current and that related tasks are generated appropriately.

Uploaded by

gurusandnew
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Apex Trigger Code

The document contains two Salesforce Apex triggers for managing project statuses and task creation. The first trigger updates the status of a project based on its start and end dates, while the second trigger creates tasks linked to project milestones after a project is inserted or updated. Both triggers ensure that project statuses are current and that related tasks are generated appropriately.

Uploaded by

gurusandnew
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//1st Scenario

trigger updatingStatus on project__c (before insert, before update) {


for(project__c v : [Link]){
// checking for a condition

if(v.StartDate__c < [Link]() && v.status__c !='In Progress'){


v.status__c ='In Progress';
}
if (v.EndDate__c <[Link]() && v.status__c !='Completed'){
v.status__c ='Completed';

}
}
}

//2nd Scenario

trigger taskCreation on project__c (after insert , after update) {


//Listing Task to insert
List<Task__c> taskToInsert = new List<Task__c>();
// collecting all project ids for task creation
Set<ID> projectIds = new set<ID>();

// Map to track which record is updated


Map<Id,project__c> projectsToUpdate = new Map<Id,project__c> ();
for (project__c v : [Link] ) {
if ([Link] || v.Milestone__c !=
[Link]([Link]).Milestone__c){
[Link]([Link]);
[Link]([Link] ,v);

}
}
//Query the Milestone for a specified project

Map<Id,List<string>> projectMilestones = new Map<Id,List<string>>();


for(project__c v : [select ID , Milestone__c from project__c where Id
IN :projectIds ]){
if(![Link](v.Milestone__c)){
[Link]([Link], v.Milestone__c.split(','));
}else{
[Link]([Link], new List<string>());
}
}
//creating Task for Each project
for(Id projectid : projectIds){
List<string> milestones = [Link](projectId);
for(string milestone : milestones ){
Task__c task = new Task__c();
task.project__c = projectId;
task.Milestone__c = [Link]();
task.status__c = 'Not Started';

[Link](task);
}
}
if (![Link]()){
insert tasksTOInsert;
}

You might also like