You need to sign in to do that
Don't have an account?

trigger Relationship Field
List<Course_Allocation__c> allocateList = new List<Course_Allocation__c>() ;
for(Lecturer__c lec: Trigger.new){
myList.add(new Course_Allocation__c(Name = lec.Name, Full_Name__c = lec.Last_Name__c,
Email__c = lec.Email__c, Mobile_Number__c = lec.Mobile_Number__c,
Department__c = lec.Department__r.Name));
}
But after insertion Department__c field is empty, why?
You will need to gather all the Department__c IDs in a list and then perform a SOQL query, querying for the data you need from these records, i.e. the Name values.
I hope this helps.
Yp it helped, But Pls could u scramble how the code could look like?
I agree with Johan, For lookup field you just have to give id of lookup record, not the lookup name.
Try this:
Hope it helps.
Compile Error:
Invalid foreign key relationship:
Lecturer__c.Department__c
To clearify, Department__c is a Child of Lecturer__c
>>>>>What i intend to achieve is
Department__c = Department__r.Name
i.e. Department__c should hold the Nave value which happens to be a forien key in Lecturer__c