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
prasad@s.ax832prasad@s.ax832 

How to populate object types to a picklist

My requirement is

1) I have a custom Object "objectA"

2) I have also created different custom objects types "CustomCar", "CustomBus", "CustomTruck" and there could be more like these. 

3) Is there a way to create a picklist or something similar in objectA that has all these object types populated from step 2, so that when i am creating an object of type objectA i can select these object types and save? 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
NBlasgenNBlasgen

Why are Truck, Car, Bus three separate things?  So I'd take a step back and look at doing this using Record Types and then some custom Page Layouts.  You can have a single dropdown called Vehicle Type and then if it's a Car, then only the Car fields show, if it's a Van then the Van fields show, etc.

All Answers

b-Forceb-Force

answer to first question populating Sobject List in picklist

 

List<SelectOption> options = new List<SelectOption>();
        Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        for(String name:schemaMap.keySet()){
            options.add(new SelectOption(name,name));// availObjList.add(name); 
        } 
        return options;

 

bind this "options" in your VF page

use appropriate filter for populating option element

 

Hope This will help you

Thanks,

Bala

 

 

 

NBlasgenNBlasgen

Why are Truck, Car, Bus three separate things?  So I'd take a step back and look at doing this using Record Types and then some custom Page Layouts.  You can have a single dropdown called Vehicle Type and then if it's a Car, then only the Car fields show, if it's a Van then the Van fields show, etc.

This was selected as the best answer
prasad@s.ax832prasad@s.ax832

Thank you Bala.

prasad@s.ax832prasad@s.ax832

Thank you NBlasgen for the solution.