0

I have an apex class which contains the method with parameter(code below). I'm calling this method from a trigger after update and the method makes some updates to a couple objects. My issue is that only one of the updates operations is actually made (the first update operation) I have looked at the debug logs in developer force and can verify that the code makes the update for some reason it just isn't commited :

public exception updateTasks(project__c p){
    // get all related tasks with Close date of null and task master not null
    list<project_task__c> ptProcessList = new list<project_task__c>();
    list<project_task__c> ptProcessOut = new list<project_task__c>();
    list<project_milestone__c> pmProcessOut = new list<project_milestone__c>();
    map<id,project_milestone__c> pmProcessMap = new map<id,project_milestone__c>();
    set<id> ptmIdSet = new set<id>();
    set<id> pmmIdSet = new set<id>();
    map<id,project_task_master__c> ptmMap = new map<id,project_task_master__c>();
    map<id,project_milestone_master__c> pmmMap = new map<id,project_milestone_master__c>();

    map<id,project_task__c> ptProcessMap = new map<id,project_task__c>(); //added Martin
    // add project task master id to set
    for(project_task__c pt : [select id,target_start_date__c,target_finish_date__c,ownerid,project_milestone__c,project_milestone__r.deadline_date__c,project_task_master__c,project_task_master__r.project_milestone_master__c from project_task__c where project__c = :p.id and completed_date__c = null and project_task_master__c !=null]){
        ptmIdSet.add(pt.project_task_master__c);
        pmmIdSet.add(pt.project_task_master__r.project_milestone_master__c);
        ptProcessList.add(pt);
    }
    // loop though project task masters and add to map
    for(project_task_master__c ptm : [select id,name,days_from_milestone_deadline_date__c,days_duration__c,specific_user__c,specific_user__r.isActive,related_user__c,assign_to_queue__c from project_Task_master__c where id in :ptmIdSet]){
        ptmMap.put(ptm.id,ptm);
    }
    // loop through project milestone masters and add to map
    for(project_milestone_master__c pmm : [select id,name,days_from_selected_field__c,selected_field__c from project_milestone_master__c where id in :pmmIdSet]){
        pmmMap.put(pmm.id,pmm);
    }
    // loop through project tasks and update owners and dates if required
    for(project_task__c ptLoop : ptProcessList){
        system.debug('In PTLOOP '+ptLoop);
        if(ptmMap.get(ptLoop.project_task_master__c)!=null){
        //Update ownership
            assignOwner(ptmMap.get(ptLoop.project_task_master__c));
            if(assignedOwnerid != null) ptLoop.OwnerId = assignedOwnerId;
            if(assignedError != null) ptLoop.Assignment_Error__c = assignedError;
        // update Due Dates         
        if(ptLoop.project_milestone__r.deadline_date__c != null){

            //only calc dates if update baseline dates not equal to no
            if(p.Update_Baseline_Dates__c =='Yes'){
                // code to update milestone date before task dates
                if(pmmMap.get(ptLoop.project_task_master__r.project_milestone_master__c)!=null&&ptLoop.Project_Milestone__c!=null){
                    calcDeadlineDate(pmmMap.get(ptLoop.project_task_master__r.project_milestone_master__c));
                    project_milestone__c pmOut = new project_milestone__c(id=ptLoop.project_milestone__c);

                    pmOut.deadline_date__c = deadlineDate;
                    pmProcessMap.put(pmOut.id,pmOut);


                date dlDate = deadlineDate;
                calcdueDate(ptmMap.get(ptLoop.project_task_master__c),dlDate);
                //mirror start
                project_task__c ptOut = new project_task__c(id=ptLoop.id);
                ptOut.target_finish_date__c = finishDate;
                ptOut.target_start_date__c = startDate;
                ptProcessMap.put(ptOut.id,ptOut);
                //mirror end 
                ptLoop.target_finish_date__c = finishDate;
                ptLoop.target_start_date__c = startDate;
                system.debug('IN Date Update startDate:'+startDate);
                system.debug('IN Date Update finishDate:'+finishDate);
                }
            }
        }

        ptProcessOut.add(ptLoop);

        System.debug('the ptProcessOut is ' + ptProcessOut);
        }

    }

   // write out processed tasks and milestones
    try {
        for(id pmId : pmProcessMap.keySet()){
            pmProcessOut.add(pmProcessMap.get(pmId));
        }
        update pmProcessOut;
        update ptProcessOut;
        return null;
    } catch(exception e) {
        return e;
    }    

}

Below is my trigger to make the call to the Class

trigger updateDueDates on Project__c (after update) {

set<id> projectId = new set<id>();
map<id,project__c> projectMap = new map<id,project__c>();

project__c[] proj = Trigger.new;    

for(project__c projs : proj){

    projectId.add(projs.id);
    system.debug('the projectid set is ' + projectId);
}
for(project__c pro : [select id,name, Update_Baseline_Dates__c,Target_Go_Live_Date__c from project__c where id in :projectId]){
     projectMap.put(pro.id,pro);
     system.debug('this is the map for the project: '+projectMap);


     ApexPAges.StandardController sc = new ApexPages.StandardController(projectMap.get(pro.id));

    ProjectTaskExtension projExtClass = new ProjectTaskExtension(sc);
    projExtClass.updateTasks(projectMap.get(pro.id));
    }
}

Any suggestions are welcome. Thanks.

2
  • did you check in debug log that you have reached the first update statement? – Bforce Jun 27 '14 at 19:55
  • thanks @BaskaranS. I figured out what the issue was - for some reason the log would display as success and other times it showed as Internal Salesforce error. I reviewed the logs again and realized that there was another trigger on a different object which was also performing similar updates to the object I'm trying to update each time an edit was made.I made some changes to the other trigger and everything is all good in my jungle again. – sw6 - KTBFFH Jun 27 '14 at 20:45
1

I figured out what the issue was - for some reason the log would display as success and other times it showed as Internal Salesforce error. I reviewed the logs again and realized that there was another trigger on a different object which was also performing similar updates to the object I'm trying to update each time an edit was made.I made some changes to the other trigger and everything is all good in my jungle again. Thanks.

3
  • Great! Good to hear that you solved the issue. – Bforce Jun 27 '14 at 20:47
  • This seems to be a interesting scenario so i upvoted your answer... – Bforce Jun 27 '14 at 20:48
  • Thanks Bask. It was interesting.I earned my pay for the day figuring it out. :) – sw6 - KTBFFH Jun 30 '14 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.