• erakan
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

Hi everybody. We have a trigger on task object which works before insert and changes WhoId value like this:

trigger x on Task (before insert ) {
	Set<String> taskIds = new Set<String> ();
	for(Task t : trigger.new)
		taskIds.add(t.WhatId);
	Map<id, Custom_Object__c> mas = new Map<id, Custom_Object__c>([Select Id, Account__r.PersonContactId From Custom_Object__c where Account__r.IsPersonAccount = true and Id in : taskIds]);
	for(Task t : trigger.new) {
		Custom_Object__c a = mas.get(t.WhatId);
		if(a == null) continue;
		t.WhoId = a.Account__r.PersonContactId;
	}
}

 

When I create a task record. The created tasks whoId field is always NULL. When I check the debug logs, I can clearly see this trigger works and assings a new whoid value. But somehow in the end, it always returns to null and there are no errors, or warnings...

 

When I run someting like update new Task(ID='XXX', WhoID='YYY'); (where the values of XXX is a Task ID and YYY is a PersonAccount Contact ID) from the developer console, I can see that WhoID value is changing.

 

We are using Person Accounts. The Custom_Object__c has a lookup field for Account object named Account__c. 

 

What do you think, what is the problem of this code?

  • November 18, 2012
  • Like
  • 0

Hi everybody. We have a trigger on task object which works before insert and changes WhoId value like this:

trigger x on Task (before insert ) {
	Set<String> taskIds = new Set<String> ();
	for(Task t : trigger.new)
		taskIds.add(t.WhatId);
	Map<id, Custom_Object__c> mas = new Map<id, Custom_Object__c>([Select Id, Account__r.PersonContactId From Custom_Object__c where Account__r.IsPersonAccount = true and Id in : taskIds]);
	for(Task t : trigger.new) {
		Custom_Object__c a = mas.get(t.WhatId);
		if(a == null) continue;
		t.WhoId = a.Account__r.PersonContactId;
	}
}

 

When I create a task record. The created tasks whoId field is always NULL. When I check the debug logs, I can clearly see this trigger works and assings a new whoid value. But somehow in the end, it always returns to null and there are no errors, or warnings...

 

When I run someting like update new Task(ID='XXX', WhoID='YYY'); (where the values of XXX is a Task ID and YYY is a PersonAccount Contact ID) from the developer console, I can see that WhoID value is changing.

 

We are using Person Accounts. The Custom_Object__c has a lookup field for Account object named Account__c. 

 

What do you think, what is the problem of this code?

  • November 18, 2012
  • Like
  • 0