You need to sign in to do that
Don't have an account?
kumarcrm bingi
Variable does not exist: NPS_Id__c
Hi,
I am writting trigger in I 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)
This is my trigger
trigger updateNpsid on shareholder__c (before insert,before update) {
List<id> ConList = new List<id>();
for(shareholder__c sh:Trigger.New){
ConList.add(sh.Contact_Name__c);
}
List<Contact> lc = [Select NPS_Id__c,NPSlookup__c From Contact Where id IN : ConList];
for(shareholder__c sh:Trigger.New){
sh.NPS_Id1__c = lc.NPS_Id__c;
}
}
Error is Variable does not exist: NPS_Id__c
Alredy i am create the field in contact
I am writting trigger in I 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)
This is my trigger
trigger updateNpsid on shareholder__c (before insert,before update) {
List<id> ConList = new List<id>();
for(shareholder__c sh:Trigger.New){
ConList.add(sh.Contact_Name__c);
}
List<Contact> lc = [Select NPS_Id__c,NPSlookup__c From Contact Where id IN : ConList];
for(shareholder__c sh:Trigger.New){
sh.NPS_Id1__c = lc.NPS_Id__c;
}
}
Error is Variable does not exist: NPS_Id__c
Alredy i am create the field in contact
In the above line, lc refers to the list. You should change it to lc[0].NPS_Id__c
Please mark this as the best answer if it resolves your problem.
Trigger is working good but my requrment is not fulfilled. Shareholder create a record they throw exception Apex trigger updateNpsid caused an unexpected exception, contact your administrator: updateNpsid: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 1: Trigger.updateNpsid: line 8, column 1
AND Another issue is
List<id> ConList = new List<id>();
for(shareholder__c sh:Trigger.New){
ConList.add(sh.Contact_Name__c);
}
List<Contact> lc = [Select NPS_Id__c,NPSlookup__c From Contact Where id IN : ConList];
for(shareholder__c sh:Trigger.New){
sh.NPS_Id1__c = lc[1].NPS_Id__c;
}
}
I can mode trigger array is taken to [0] but still error is showing. i write the corrent but they still showing error