We have Stakeholder object that is the related list to Opportunity and Contact. On Contact detail page, we have NPS ID field on the Contact detail page that is look up to the Voice of NPS object (Customer Object). The following code will get the NPS ID field value from the Contact detail page in the Stackholders page which we can able to clickable.
Create NPS Id 1 field on the stackholders object which is the look up to the Voice of NPS object (Customer Object)
triggerUpdateNPSid on Stakeholder__c(before insert, before update) {
List < id > ConList = new List < id > ();
for (Stakeholder__csh: Trigger.New) {
ConList.add(sh.Contact_Name__c);
}
List < Contact > lc = “Select NPS_Id__c From Contact Where id IN: ConList”;
for (Stakeholder__csh: Trigger.New) {
sh.NPS_Id1__c = lc” 0”.NPS_Id__c;
}
}
trigger UpdateNPSid on Stakeholder__c(before insert, before update) {
List < id > ConList = new List < id > ();
map < id, id > map_NPS_Cont = new map < id, id > ();
for (Stakeholder__c sh: Trigger.New) {
if (sh.Contact_Name__c != null)
ConList.add(sh.Contact_Name__c);
}
List < Contact > lc = “Select Id, NPS_Id__c From Contact Where id IN: ConList”;
if (lc != null && lc.size() > 0) {
for (Contact c: lc) {
If(c.NPS_Id__c != null) {
map_NPS_Cont.put(c.Id, c.NPS_Id__c);
}
}
for (Stakeholder__c sh: Trigger.New) {
if (sh.Contact_Name__c != null)
sh.NPS_Id1__c = map_NPS_Cont.get(sh.Contact_Name__c);
else
sh.NPS_Id1__c = null;
}
}
}