We have 2 custom objects Objective and Publisher both are unrelated object, we have a lookup to Publisher on Objective object. We have one Active Publisher for each campus. We are trying to populate active Publisher on to the lookup field on Objective based on Campus. I'm new in Apex, I'm trying to figure this out by writing a trigger on Objective. The below code is not populating the field Publisher name look up field. I could be completely lost in here. Can someone please guide on how to achieve this?
trigger UpdateObj on Objective__c (after insert) {
Set<id>ids=new set<id>();
For(Objective__c obj:trigger.new){
if(obj.Request_Center_LookUp__c!=Null){ //Request center is a parent object of Objective
ids.add(obj.id);
}
if(!ids.Isempty()){
list<publisher__c> NewPL=[select id,name from publisher__c where Mediapartner__c= TRUE AND
Campus_Text__c = 'RUMC' AND Publisher_Status__c = 'Active' AND id in:Ids];
for(publisher__c publisher: NewPL){
for(Objective__c obj1: trigger.new){
publisher.Id= obj.Publisher_Name__c;
}
}
}
}
}