0

I have a trigger on provision object to create a user record when provision record gets created on page layout i have a field called model if user select model user it should assign the profile from user and assign it to new user ...but it not assigning and toughing a error that profile id is empty when i am trying to to with query it is working perfectly but i don't want to user query here . how can i avoid query here:

User M=[Select id,Name,ProfileId, from User where Id =: PR.Model__c];
PR.ProfileId = M.Profile Id///THis is working 

i am trying to avoid a query and writing like this:

usr.ProfileId = PR.User__r.ProfileId; 
// it is not fetching the profile and thoughing and error saying profile id is missing

1 Answer 1

1

You cannot access relationship fields in trigger, you can only access fields of the object that are in transaction.

So in your case, you will have to write a SOQL on User object to get the profileId or any other relationship fields.

2
  • Presume you meant "to get the profile Id"?
    – Keith C
    Commented May 23, 2019 at 7:19
  • @KeithC Yup I meant ProfileId. Thanks for the observation, updated the answer Commented May 23, 2019 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .