You need to sign in to do that
Don't have an account?
illegal assignemnt illegal assignment from schema.sobjectfield to id
Hi there,
I have two custom objects. The Investigation__c is the parent object, and the Time_Entry_Recap_Report__c is the child object. What I want to have happen is when the parent record (Investigation) is initially created, I want to create an initial entry in the 'Time_Entry_Recap_Report__c' with 15 minutes of time worked and a description of the task being 'Opened new investigation'. I'm trying to figure out how to relate the Child record to the parent record when I create the entry in the trigger. The object 'Time_Entry_Recap_Report__c' is already defined as a child to the parent, but trying to insert the record without a reference to the 'Investigation_Time_Entry__c' field within the 'Time_Entry_Recap_Report__c' object didn't work either. The Error I am getting is "Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 8 column 7. Any assistance would be greatly appreicated.
I have two custom objects. The Investigation__c is the parent object, and the Time_Entry_Recap_Report__c is the child object. What I want to have happen is when the parent record (Investigation) is initially created, I want to create an initial entry in the 'Time_Entry_Recap_Report__c' with 15 minutes of time worked and a description of the task being 'Opened new investigation'. I'm trying to figure out how to relate the Child record to the parent record when I create the entry in the trigger. The object 'Time_Entry_Recap_Report__c' is already defined as a child to the parent, but trying to insert the record without a reference to the 'Investigation_Time_Entry__c' field within the 'Time_Entry_Recap_Report__c' object didn't work either. The Error I am getting is "Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 8 column 7. Any assistance would be greatly appreicated.
trigger CreateTimeEntry on Investigation__c (after insert) { List<Time_Entry_Recap_Report__c> entryList = new List<Time_Entry_Recap_Report__c>(); for(Investigation__c InvestigationObj : Trigger.new){ Time_Entry_Recap_Report__c entry = new Time_Entry_Recap_Report__c(); entry.Hours_Worked__c = '00'; entry.Minutes_Worked__c = '15'; entry.Work_Performed__c = 'Opened new investigation'; entry.Investigation_Time_Entry__c = Investigation__c.NAME; entryList.add(entry); } if(entryList.size()>0){ upsert entryList; } }
As @Varaprasad suggested that use the id instead of Name..name is not a valid type for the ID.. and don't use upsert because you are executing trigger only on Insert.. I have modified the code that may help you..
Thanks,
Prashant
All Answers
Hope this helps you.
please let me know in case of any other assistance
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
As @Varaprasad suggested that use the id instead of Name..name is not a valid type for the ID.. and don't use upsert because you are executing trigger only on Insert.. I have modified the code that may help you..
Thanks,
Prashant