function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alvin TaiAlvin Tai 

How do I use a trigger to update picklist values with records from a separate custom object?

This sounds like what I need, but I can't get it to work: http://salesforce.stackexchange.com/questions/27327/how-to-update-picklist-value-dynamically-from-custom-object

rigger populatePicklist on Code__c(After Insert){

  List<selectoption> newCodes= new List<selectoption> (SELECT Picklist__c from Unit__c where Unit__c.Part__r=Code__c.Part__r);
  
  newCodes.add(trigger.new[0].Name)
  update newCodes.values();


}

I'm pretty new to salesforce, so I'm not really sure if this is even the right direction...
Sumitkumar_ShingaviSumitkumar_Shingavi
I think you are trying to write Apex Trigger for your requirement which is wrong! you need to write a apex class and a vf page to meet this requirement.

The link your are refering to have enough details on how to do it!

Note: You can never over-ride picklist values of a Packlist field on some object directly from Apex code. You MUST need to have that picklist as custom picklist where you need to use Apex and VF.
Alvin TaiAlvin Tai
So there's no way to do this? (written in comments)

//After the insert of a record into CODE object {
  
  //Query database for picklist values
  //add inserted record to the end of the picklist values

  //update query within database

}

Again, thank you so much for your help. I've spent way too long trying to do this...


Sumitkumar_ShingaviSumitkumar_Shingavi
Yes, this is not feasible! You can do with use of Custom Apex class and VF page if you MUST need it!

PS: if this answers your question then hit Like and mark it as solution!