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
kavya.ax1320kavya.ax1320 

Required Fields of object into Select List.

Hi !!!

 

Is there a possibility to get all the required fields of an object into select List.?

 

Example

All the Required Fields of the Account  to be listed into a select list.

 

Thanks in Advance.

Manju

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

PremanathPremanath

Hi follow This code it may be help ful to you

 

<apex:page controller="exampletest">
<apex:form >
<apex:pageBlock >
<apex:repeat value="{!acc}" var="a">
{!a.name}   <!-- You can put whatever required fields-->
{!a.phone}
{!a.fax}
</apex:repeat>

</apex:pageBlock>
</apex:form>
</apex:page>

 

 

public class exampletest {
public string query{get;set;}
public Account acc{get;set;}
public exampletest ()
{
Map<string,Schema.SObjectField> mpConField=Account.getSObjectType().getDescribe().fields.getMap();
Set<string> originalvalues = new Set<String>();
originalvalues = mpConField.keySet();
query='select ';
for(string f : originalvalues)
{
Schema.DescribeFieldResult fldResult=mpConField.get(f).getDescribe();
if(query=='select ')
{
query=query+string.valueof(fldResult.getName());
}
else
{
query=query+','+string.valueof(fldResult.getName());
}
}
query=query+' from Account limit 1';
acc=Database.query(query);
}
}

kavya.ax1320kavya.ax1320

Hi Premanath,

 

Thanks for the reply, but as per my understanding to the above code. It would return all the fields of the Account object.

I need only the required fields of the account object.

 

Thanks.

 

 

PremanathPremanath
This was selected as the best answer
kavya.ax1320kavya.ax1320

Hi Premanath,

 

Thanks, That worked..

 

Super!!!