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
sowjanya bheemasowjanya bheema 

hello all,how to create a soql on account object and create a picklist to display account name as label and phone as a value

Deepali KulshresthaDeepali Kulshrestha
Hi sowjanya,
Greetings to you!

I have created  an apex class which is returning the wrapper List of account Name and phone number. You can use this wrapper list any where as you want.
public class PickListCreation {
    public static List<AccountNameVSPhone> createPicklistMethod(){
        List<AccountNameVSPhone> AccountNameVSPhoneList = new List<AccountNameVSPhone>();
        try{
            List<Account> accountList = new  List<Account>(); 
            accountList = [SELECT Id,
                           Name,
                           Phone
                           FROM Account
                           LIMIT 50000];
            if(accountList.size() > 0){
                for(Account accobj : accountList){
                    AccountNameVSPhone obj = new   AccountNameVSPhone();
                    obj.Lavel = accobj.Name;
                    obj.Value = accobj.Phone;
                    AccountNameVSPhoneList.add(obj);
                }
            }
            System.debug('AccountNameVSPhoneList-->'+AccountNameVSPhoneList);
            if(AccountNameVSPhoneList.size() > 0){
                return AccountNameVSPhoneList;
            }
        }catch(Exception e){
            System.debug('Exception :'+e.getMessage()+' AT Line : '+e.getLineNumber());
        }
        return null;
    }
    public class AccountNameVSPhone{
        public String Lavel;
        public String Value;
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha