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
Sean ClarkSean Clark 

Apex trigger to create a task and set Assigned To, to the MVP Owner

I have created an Apex Trigger to create a Task on the MVP Object but keep getting an error.

I am trying to link the Assigned To (Lookup(user,calender))  on the Task object to the MVP Owner (Lookup(user)). 

Can anyone help correct this error? 


User-added image
User-added image
Best Answer chosen by Sean Clark
Raj VakatiRaj Vakati
Do you have access for this field on MVP__c  , and OwnerId fields on the Objects ?? 

I belive this is the issue with permissions 

All Answers

Nishant Prajapati 10Nishant Prajapati 10
Hi Sean
Please Change,
line no. 10 -: t.subject = 'You need to call '+ mvp.FirstName+ ' today';
line no. 11-: t.OwnerId = mvp.OwnerId;

 
Sean ClarkSean Clark
Hello Nishant,

There is now an error on Line no.11 - Variable does not exist: OwnerId
Sean ClarkSean Clark
Would you know how to do this? I am very new to using Apex 
 
Raj VakatiRaj Vakati
Change Line 10,11,12 with below code
 
t.subject = 'You need to call '+ mvp.FirstName+ ' today';
t.OwnerId =mpv.OwnerId ;
t.WhatId =mvp.Id ;

 
Sean ClarkSean Clark
@Raj

Line no.11 - Variable does not exist: OwnerId

The Owner I of the taks is a Lookup(User, Calander) field and the MVP Owner field is a Lookup(User).

Not sure where its going wrong or how to fix this.
Nishant Prajapati 10Nishant Prajapati 10
Hi sean
Please try to replace Line No. 11 with:
t.ownerId = trigger.newMap.get(mvp.Id).OwnerId;

 
Sean ClarkSean Clark
Hello Nishant,

Thank you for helping me with this!

i am replaced line 11 with what you advised but is still comes up with: Variable does not exist: OwnerId
Nishant Prajapati 10Nishant Prajapati 10
is your Object MVP__c is on detail side of Master-detail relationship?
Raj VakatiRaj Vakati
Do you have access for this field on MVP__c  , and OwnerId fields on the Objects ?? 

I belive this is the issue with permissions 
This was selected as the best answer
Sean ClarkSean Clark
@Raj 

Thank you for this, it was indeed due to the permissions! 

Thank you both @Raj & @Nishant for your help on this!