You need to sign in to do that
Don't have an account?
Richard Houston 20
Update child records with lookup to user object
I'm getting my feet wet trying to write my first trigger and like many others am running into some errors.
We have a custom object, Project Information, that is a child in a master-detial lookup to opportunities. I have a user lookup field on both opportunities and project information that I want to keep in sync with each other. Changes to the lookup only occur on the Opportunity record.
I'm getting an error on the code below on line 4 (obj.REO_User_Record__c=Opportunity.REO__c;), "I'llegal assignemtn from Schema.SObjectField to Id. How do I get the UserID from the opportunity lookup into the Project Information lookup?
Thanks for the help!
We have a custom object, Project Information, that is a child in a master-detial lookup to opportunities. I have a user lookup field on both opportunities and project information that I want to keep in sync with each other. Changes to the lookup only occur on the Opportunity record.
I'm getting an error on the code below on line 4 (obj.REO_User_Record__c=Opportunity.REO__c;), "I'llegal assignemtn from Schema.SObjectField to Id. How do I get the UserID from the opportunity lookup into the Project Information lookup?
Thanks for the help!
trigger UpdateREO on Opportunity (after update,after insert) { List<Project_Information__c>IstToUpdate=new List<Project_Information__c>(); for(Project_Information__c obj :[select id,name,REO_User_Record__c,Opportunity__c from Project_Information__c where Opportunity__c != null and Opportunity__c in : trigger.new]){ obj.REO_User_Record__c=Opportunity.REO__c; IstToUpdate.add(obj); } if(!IstToUpdate.isEmpty()) update IstToUpdate; }
obj.REO_User_Record__c=obj.Opportunity.owner;
All Answers
obj.REO_User_Record__c=obj.Opportunity.owner;
That was the right direction to send me in thanks!
I think this is what I need to change to make this work.
Adding in the Obj.Opportunity__r.(Field) gave the trigger the proper field reference. Where as when I started wtih the trigger it was kind of a lost reference of different data types.
Next I also had to change my select statement to include the Opportunity__r.REO__c field. Not having it in there threw an error on the Opportunity when I went to save. The error was an field reference that wasn't selected in the SOQL statement.
Thanks for the help!
Final trigger:
No I just need to try to write the test.