• Gopesh Vardhan Singh 8
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Astrea IT services


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Suppose I have to Objects , ACCOUNT and CONTACT , I want to update one of the field of Account(COUNTRY) as same as field  of the Contact's field(COUNTRY NAME) ,on the basis  of one of the  field of Contact which is of CheckBox Type.

If checkbox is ticked , only then the updation  is required.

They are related to each other through relationship.

Hi All,

 

I have a requirement to get the Selected Object's Fields in a Multi select Picklist.Currently i am able to select the Object and get its fields in a list.

 

Below is my VF Code :-

 

<apex:page Controller="Describer">
<apex:form id="Describe">
<apex:pageBlock id="block2" >
<apex:pageblockbuttons location="top" >
<apex:commandButton value="Get Describe Object Fields" action="{!showFields}"/>
</apex:pageblockbuttons>
<apex:pageblocksection >
<apex:selectList value="{!selectedObject}" size="1">
<apex:selectOptions value="{!objectNames}"/>
</apex:selectList>
</apex:pageblocksection>
<apex:pageblocksection id="fieldList" rendered="{!not(isnull(selectedObject))}">
<apex:panelBar items="{!fields}" var="fls">
<apex:panelBarItem label="{!fls.key}">{!fls.val}</apex:panelBarItem>
</apex:panelBar>
</apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Below is my Controller Code :

 

public class Describer {

private Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public List <Pair> fields {get; set;}
public List <SelectOption> objectNames {public get; private set;}
public String selectedObject {get; set;}

// Intialize objectNames and fields

public Describer() {
objectNames = initObjNames();
fields = new List<Pair>();
}
// Populate SelectOption list -

// find all sObjects available in the organization

private List<SelectOption> initObjNames() {
List<SelectOption> objNames = new List<SelectOption>();

List<String> entities = new List<String>(schemaMap.keySet());
entities.sort();
for(String name : entities)
objNames.add(new SelectOption(name,name));
return objNames;
}

// Find the fields for the selected object

public void showFields() {
fields.clear();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();

for(Schema.SObjectField sfield : fieldMap.Values()){
schema.describefieldresult dfield = sfield.getDescribe();
Pair field = new Pair();
field.key = dfield.getname();
fields.add(field);
}
}


public class Pair {
public String key {get; set;}
public String val {get; set;}
}
}