function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Devon MorancieDevon Morancie 

Assign user to ID issue

Hi all, I'm having trouble getting a user assigned to a specific ID. 
Basically, when creating a new Task, if the Owner of the Event (custom object) is a certain Id (let's call it A) then the owner of the task must be set to Id C. If the owner is Id B, then it must also be set to Id C. The Id A condition works just fine, but the condition for B does not. I am pasing the Id as a string, to a lookup field (User, Calendar), in an if statement.
if(event.Owner == 'A'){
task.Owner = 'C';}
else if (event.Owner == 'B'){
task.Owner = 'C';}

Condition A works fine, but condition B does not. In the DML insert error, it sas that the task.Owner is null, but ONLY when attempting to set with condition B. The two blocks of code are the same, and I have put  debug statements in there to check and make sure the if statements are firing correctly, and they are. Any ideas?
Łukasz JanickiŁukasz Janicki
Hi Devon,
Can you share your real code with declaring variable & insert part?
Devon MorancieDevon Morancie
I can't due to work restraints, but just imagine A, B, and C being repaced with Id strings.
Piyush Gautam 6Piyush Gautam 6
Hi Devon Morancie,

There might be a possibility that the event owner is neither A nor B. You might be testing the second scenario with the wrong event owner.
If you can provide the real code (if and else statement) with the record data then it will easy to find the issue.

I will suggest you check the event owner field value against the A and B.

Thanks
Devon MorancieDevon Morancie
I have a check in there to catch if it is neither A nor B, and that check fires off correctly when it is neither. So the A checks all work fine, The problem is that it won't *assign* the field to C when condition B is met.