• Carrie Farnsworth
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi All,

I made a simple trigger to create a task related to the Opportunity and assigned to the Opportunity Owner when a particular field on a related object is changed.  I'm getting Invalid Cross Reference: owner ID cannot be blank.  I read some other posts about the error and I somewhat know what the problem is, but I don't really understand how to fix it.  Can anyone help me please?

Here is my trigger:
trigger CreateTaskOnRed on project_cloud__Project__c (after update) {
	List<task> TasksToInsert = new List<task>();
    for (project_cloud__project__c pj: trigger.new) {
 		
        //only run if the project health is red
        if (pj.project_cloud__Health__c == 'Red') {
                      
        //compile data for affected project
			project_cloud__project__c[] pjs = [
                SELECT name, id, ccpe_ocp__Opportunity__c  
                FROM project_cloud__project__c 
                WHERE project_cloud__project__c.id 
                IN :Trigger.new];  
                 
        //create task for opportunity owner
        	task t = new task();
            t.RecordTypeId = '012i0000000xowf';
			t.ownerid = pj.ccpe_ocp__Opportunity__r.owner.id;
            t.whatID = pj.ccpe_ocp__Opportunity__r.id;
            t.ActivityDate = System.today();
            t.Subject = 'Other';
            t.Type__c = 'Other';
            t.Account_Type__c = 'Other';
            t.Drop_Type__c = 'Other';
            t.Broker_Care_Type__c = 'General Inquiries';
            t.Priority = 'High (High Priority)';
            t.Status = 'open';
            TasksToInsert.add(t);
        }            
            else{}
            if(TasksToInsert!=null && !TasksToInsert.isEmpty()){
                ProjectTriggerHelper.createTasks(TasksToInsert);
	     }
    }
}


And the helper:
 
public class ProjectTriggerHelper	{
	
	public static void createTasks(List<Task> TasksToInsert){
		try{
		       insert TasksToInsert;
		}
		catch(Exception err){
			system.debug('\n Error while creating tasks. \n'
                                  + err.getMessage() + ' \n'
                                  + err.getStackTraceString());			
		}
	}

}

 
Hi All,

I'm trying to create a trigger (or use workflow rules) to update fields on the child record of a child record and I'm not sure how to do it (if it's even possible). 

The parent object is called Project__c.  Project__c is the parent to multiple Phase__c records which are parent to multiple Task__c records. When the Project_Status__c field on Project__c is set to cancelled, all associated Task__c records (under the associated Phase__c records) should be have the checkbox field IsCompleted__c set to TRUE and N_A__c checkbox set to TRUE.  Does anyone know how I can do this?
Hi All,

I made a simple trigger to create a task related to the Opportunity and assigned to the Opportunity Owner when a particular field on a related object is changed.  I'm getting Invalid Cross Reference: owner ID cannot be blank.  I read some other posts about the error and I somewhat know what the problem is, but I don't really understand how to fix it.  Can anyone help me please?

Here is my trigger:
trigger CreateTaskOnRed on project_cloud__Project__c (after update) {
	List<task> TasksToInsert = new List<task>();
    for (project_cloud__project__c pj: trigger.new) {
 		
        //only run if the project health is red
        if (pj.project_cloud__Health__c == 'Red') {
                      
        //compile data for affected project
			project_cloud__project__c[] pjs = [
                SELECT name, id, ccpe_ocp__Opportunity__c  
                FROM project_cloud__project__c 
                WHERE project_cloud__project__c.id 
                IN :Trigger.new];  
                 
        //create task for opportunity owner
        	task t = new task();
            t.RecordTypeId = '012i0000000xowf';
			t.ownerid = pj.ccpe_ocp__Opportunity__r.owner.id;
            t.whatID = pj.ccpe_ocp__Opportunity__r.id;
            t.ActivityDate = System.today();
            t.Subject = 'Other';
            t.Type__c = 'Other';
            t.Account_Type__c = 'Other';
            t.Drop_Type__c = 'Other';
            t.Broker_Care_Type__c = 'General Inquiries';
            t.Priority = 'High (High Priority)';
            t.Status = 'open';
            TasksToInsert.add(t);
        }            
            else{}
            if(TasksToInsert!=null && !TasksToInsert.isEmpty()){
                ProjectTriggerHelper.createTasks(TasksToInsert);
	     }
    }
}


And the helper:
 
public class ProjectTriggerHelper	{
	
	public static void createTasks(List<Task> TasksToInsert){
		try{
		       insert TasksToInsert;
		}
		catch(Exception err){
			system.debug('\n Error while creating tasks. \n'
                                  + err.getMessage() + ' \n'
                                  + err.getStackTraceString());			
		}
	}

}

 
Hi All,

I'm trying to create a trigger (or use workflow rules) to update fields on the child record of a child record and I'm not sure how to do it (if it's even possible). 

The parent object is called Project__c.  Project__c is the parent to multiple Phase__c records which are parent to multiple Task__c records. When the Project_Status__c field on Project__c is set to cancelled, all associated Task__c records (under the associated Phase__c records) should be have the checkbox field IsCompleted__c set to TRUE and N_A__c checkbox set to TRUE.  Does anyone know how I can do this?