You need to sign in to do that
Don't have an account?
baller4life7
FIELDSET elements usage in APEX
Hi guys,
I have a fieldset called "States" with all 51 us states: AL__c, AR__c, AZ__c, CA__c, etc...
Now I want to add all field values and labels to an item list like this (this is pseudo-code):
for( <fieldset-element> : <all fieldset-elements>)
{
items.add(<fieldset-element>.value, <fieldset-element>.label);
}
How can I do that in Apex?
Thanks
Josh :-)
Right now Field Set are not available in APEX, so you can not loop over field set in Apex, but what you can do is create a Map where key is FieldAPIName , and Value is Label and use this map in VFP to get Label, like
And Use this Map in field set like
let me know if any issues in it.
Thank you Shashikant! That's actually a good idea, but not completely the solution I am looking for.
What I basically want to do is have less work in writing apex code.
I don't want to write:
1. SELECT AL__c, AR__c, (... and the other 49 states) FROM Account
2. items.add(account.AL__c, account.AL__c.label()); <- Pseudo-Code
items.add(account.AR__c, account.AR__c.label()); <- Pseudo-Code
...
I want to reduce the work to a few lines!
I want my code to do something like this:
Is there a possibility to make it work like this? Or even a better solution?
I know my response is a little late, but hopefully this helps:
Rtuttle, thank you for providing this solution! I won't be able to test it now, because I already implemented my version. If somebody tests the code and it works, please let us know by writing a reply here and I will accept it as a solution.
Josh :-)
Here is a version you can test in an anonymous apex (via system log, eclipse, or workbench). It would be hard for anyone else to test as we don't have those fields in our org. All you need to add into this to test is an account id at the top, then execute it anyonymously. I'm glad to hear you were able to get a solution that worked!
Hi Please help me on this.
I want to query if the data type of my field is a pick list
here is what i am doin
Schema.DescribeSObjectResult objSchema = Opportunity.sObjectType.getDescribe();
Map<String, Schema.SObjectField> fieldMap = objSchema.fields.getmap();
system.debug ('XXXXXFields'+ fieldMap);
for (String fieldName : fieldMap.keySet()) {
fieldMap.get(fieldName).getDescribe().getpicklistvalues();//It provides to get the object fields label.
if(get(fieldname).getpicklistvalues()){
}
I dont know if this is right.
Please help
Hi Adil,
So close with your code. Check out this alternate function off of the field describe called getType. It returns an enum of the field types.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm#apex_displaytype