Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the values in the option list in Apex in Salesforce

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article examines "how to get values from the list of options in Apex in Salesforce". The content is detailed and easy to understand, and friends who are interested in "how to get the values in the list of options in Apex in Salesforce" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's learn more about "how to get the values in the option list in Apex in Salesforce" with the editor.

It is sometimes encountered in Apex that you need to get the values in the option list field. For example, there may be multiple provinces under a provincial field, such as Heilongjiang, Beijing, Henan and so on. How do you show all the values?

When Xiao Meow first came into contact with this situation, it was like this, ↓.

ManProvinceOption = new List (); ManProvinceOption.add (new SelectOption ('all', 'all'); ManProvinceOption.add (new SelectOption ('Shandong', 'Shandong'); ManProvinceOption.add (new SelectOption ('Heilongjiang', 'Heilongjiang'); ManProvinceOption.add (new SelectOption ('Jilin', 'Jilin'); ManProvinceOption.add (new SelectOption ('Jiangsu', 'Jiangsu')) ManProvinceOption.add (new SelectOption ('Shenzhen', 'Shenzhen'); ManProvinceOption.add (new SelectOption ('Shanghai', 'Shanghai')); ManProvinceOption.add (new SelectOption ('Zhejiang', 'Zhejiang')); ManProvinceOption.add (new SelectOption ('Fujian', 'Fujian'); ManProvinceOption.add (new SelectOption ('Guangdong', 'Guangdong')); ManProvinceOption.add ('Guangxi', 'Guangxi')) ManProvinceOption.add (new SelectOption ('Dalian', 'Dalian'); ManProvinceOption.add ('Anhui', 'Anhui'); ManProvinceOption.add (new SelectOption ('Gansu', 'Gansu')); ManProvinceOption.add (new SelectOption ('Shenyang', 'Shenyang'); ManProvinceOption.add (new SelectOption ('Jiangxi', 'Jiangxi'); ManProvinceOption.add ('Shanxi', 'Shanxi')) ManProvinceOption.add (new SelectOption ('Xinjiang', 'Xinjiang'); ManProvinceOption.add ('Hunan', 'Hunan'); ManProvinceOption.add (new SelectOption ('Tianjin', 'Tianjin')); ManProvinceOption.add (new SelectOption ('Henan', 'Henan'); ManProvinceOption.add ('SP headquarters','SP headquarters')) ManProvinceOption.add (new SelectOption ('Yunnan', 'Yunnan'); ManProvinceOption.add (new SelectOption ('Hubei', 'Hubei')); ManProvinceOption.add (new SelectOption ('Beijing', 'Beijing')); ManProvinceOption.add (new SelectOption ('Sichuan', 'Sichuan'); ManProvinceOption.add ('Inner Mongolia', 'Inner Mongolia')) ManProvinceOption.add (new SelectOption ('Shaanxi', 'Shaanxi'); ManProvinceOption.add (new SelectOption ('Hebei', 'Hebei'); ManProvinceOption.add ('GIR headquarters', 'GIR headquarters'); ManProvinceOption.add (new SelectOption ('Guizhou', 'Guizhou'); ManProvinceOption.add ('Chongqing', 'Chongqing')) ManProvinceOption.add (new SelectOption ('Qinghai', 'Qinghai')

Writing data in this way is dead data. If there are some big changes in the future, how troublesome will it be?

Meow used to learn Java, when we need a drop-down list is queried from the database table, and then display.

Xiao Meow inquired about it from the Internet, and there is indeed this kind of operation in salesforce. Here is the code for my friends.

It uses Schema.DescribeFieldResult to get the description of the option list field getDescribe ().

Example:

ManProvinceOption= new List (); Schema.DescribeFieldResult fieldResult2 = OPDPlan__c.ProvinceOption__c.getDescribe (); List ple2 = fieldResult2.getPicklistValues (); for (Schema.PicklistEntry f: ple2) {ManProvinceOption.add (new SelectOption (f.getLabel (), f.getLabel ();}

Format:

/ / the variable name of the variable that holds the data is 0 = new List (); / / gets the value of the Schema.DescribeFieldResult variable name of the object's option list field 1 = object. Option list field .getDescribe (); List variable name 2 = variable name 1.getPicklistValues (); for (Schema.PicklistEntry f: variable name 2) {variable name 0.add (new SelectOption (f.getLabel (), f.getLabel () } about how to get the values in the list of options in Apex in Salesforce, so much for sharing here. I hope the above content will improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report