Here i am trying to get owner name value from child object incident , OwnerId is populating correctly but when i tried with Owner.Name
, value is coming null in debug log.
Please find my piece of code below and suggest me how to get incident Owner Name in case record Incident_Owner__c
field.(Parent : case Child : Incident)
trigger Updateincident on BMCServiceDesk__Incident__c (after insert, after update)
{
//You want it on update too, right?
Map<ID, Case> parentCases = new Map<ID, Case>(); //Making it a map instead of list for easier lookup
List<Id> listIds = new List<Id>();
for (BMCServiceDesk__Incident__c childObj : Trigger.new) {
listIds.add(childObj.Cases__c);
System.debug('@@@@@@@@@@@@'+listIds);
}
parentCases = new Map<Id, Case>([SELECT id,Helpdesk_Case_Status__c,Helpdesk_Case_Resolution__c,(SELECT ID,Name, BMCServiceDesk__FKStatus__c,Owner.Name,BMCServiceDesk__Status_ID__c,BMCServiceDesk__incidentResolution__c FROM Incidents__r) FROM Case WHERE ID IN :listIds]);
System.debug('@@@@@@@@@@@@'+parentCases );
for(BMCServiceDesk__Incident__c inc: Trigger.new){
Case myParentCse = parentCases .get(inc.Cases__c);
myParentCse.Helpdesk_Case_Resolution__c = inc.BMCServiceDesk__incidentResolution__c;
myParentCse.Helpdesk_Case_Status__c = inc.BMCServiceDesk__Status_ID__c;
myParentCse.Incident_Owner__c = inc.Owner.Name;
System.debug('@@@@@@@@@@@@'+myParentCse.Incident_Owner__c);
myParentCse.Incident_Number__c = inc.Name;
System.debug('@@@@@@@@@@@@'+myParentCse.Helpdesk_Case_Resolution__c);
}
update parentCases.values();
System.debug('@@@@@@@@@@@@'+parentCases.values());
}
Cases
can have manyBMCService Incidents
how do you know whichBMCService incident
data should be on the case?