You need to sign in to do that
Don't have an account?
NullPointer Exception with Trigger
Hi All
I am willing to dynamically update the Picklist (multi select) of one custom object, whenever a new record is added to another custom object.
I am writing the following trigger -
trigger PMs_MultiPick_Update on Portfolio_Managers__c (after update, after insert, after delete) {
Set<String> pmlist;
List<Portfolio_Managers__c> pm= new List<Portfolio_Managers__c>();
for(Portfolio_Managers__c p : [SELECT name from Portfolio_Managers__c]){
pmlist = new Set<String> (p.Name.split(';'));
}
PM_Requests__c pmreq;
String pm_entire_list;
for (String pml : pmlist){
pm_entire_list = ';' + pml;
}
pmreq.multi_test__c = pm_entire_list;
}
I am getting the runtime exception as -
System.NullPointerException: Attempt to de-reference a null object
at line 15, column 6, which is -
pmreq.multi_test__c = pm_entire_list;
Please guide me on where the problem is?
Thanks
The error is at this line.....
PM_Requests__c pmreq;
When you declare such a statement, the variable will hold nothing.... And if you say pmreq.field it is obviously an error as no record is associated to pmreq...
So either write a query and put a record in pmreq or create a new one...
Hope this helps you...
Hi.. thanks for reply.
If I write it as -
PM_Requests__c pmreq= new PM_Requests__c();
Will that serve my purpose as per what I am willing to do?
Thanks
Hey..
I tried to delete a record from 1 of my custom object to check if picklist (multi select) in another object is dynamically populated. But it does not get populated with any of the values.
Can you try to look my trigger code once and tell me where I am going wrong.
Any help will be appreciated.
Thanks
The 2 objects I am using are -
1. Portfolio_Managers__c (I am writing trigger on this object)
2. PM_Requests__c (this is the object which contains picklist(multiselect) whose available values should be populated dynamically as and when records are inserted, updated or deleted from my 1st object Portfolio_Managers__c).
Let me know if I am making sense?
Thanks
Hello.
Can anyone try to guide me for this.
Thanks
Hi,
From what i understood... You have the first object Portfolio_Managers__,, when a new record is inserted into this object you want the name of the record to be added to the picklist value multi_test__c in another object PM_Requests__c...
Well, as far as i know that is not possible... You can add values to a picklist only by going to setup....
What we can actually do is update the value of the multi-select picklist... but we do not have programatic control on the list of values the picklist should contain...
But this is what i know.. if you do find a solution pls let me know..
Thanks,