1

Visualforce code:

<apex:page controller="OnlineAdmission">
    <apex:form>
        <style>
            tr.dr1 {
                background-color: #CCFF66;
                color: blue;
                font-size: 20px
            }
            tr.dr3 {
                background-color: Yellow;
                color: blue;
                font-size: 20px
            }
            tr.dr1:hover {
                background-color: #00FFFF;
            }
            tr.dr3:hover {
                background-color: #FF3397;
            }
        </style>
        <apex:pageBlock>
            <table class="List" border="0" cellpadding="5" cellspacing="1">
                <tr class="dr3">
                    <th>Welcome to Devry University</th>
                    <th>Main Branch office</th>
                </tr>
                <tr class="dr1">
                    <td>Candidate Name:</td>
                    <td>
                        <apex:inputtext value="{!A.Candidate_Name__c}" />
                    </td>
                </tr>
                <tr class="dr1">
                    <td>Online Courses:</td>
                    <td>
                        <apex:selectlist value="{!A.Online_Courses__c}" />
                    </td>
                </tr>
                <apex:pageBlockButtons>
                    <apex:commandButton value="Save" action="{!save}" />
                    <apex:commandButton value="Save&New" action="{!savenew}" />
                </apex:pageBlockButtons>
            </table>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Code:

public class OnlineAdmission { 
public Obj_A__c A{set;get;} 
public list<Obj_A__c> B {set;get;}

 public OnlineAdmission() { 
    A=new Obj_A__c(); 
    B=[select id,Online_Courses__c from Obj_A__c ]; 
 } 

    public pagereference save() { 
        insert A; 

        pagereference pg=new pagereference('/'+A.id); 
        return pg; 
        } 

        public void savenew() {
            insert A; A.clear(); 
        }
}
  • 1
    AzuSfdc - you might want to learn how to format your code in the question -- click Edit, highlight the code statements, and then select the button that looks like 1's and 0's – cropredy Dec 11 '14 at 19:03
  • And please take some time to read this.. salesforce.stackexchange.com/help/how-to-ask People will respond better when it looks like you try to ask a good question – EricSSH Dec 11 '14 at 19:07
  • I had Struck here could any one help me please.............! – Abdul Azeem Dec 14 '14 at 13:29
  • If Online_Courses__c is a picklist field, then <apex:inputField value="{!A.Online_Courses__c}" /> should work. – Keith C Dec 14 '14 at 14:11
  • @AzuSfdc - You took all this effort to ask the question and someone was kind enough to take the time to provided an answer to you. Could you please either accept it or respond to the answer so the community will know if it solved your problem and your question will stop being bumped as needing an answer? – Eric Dec 14 '14 at 15:23
0

If you change your Visualforce code from a apex:selectList to an apex:inputField the Visualforce engine will take care of rendering the correct picklist values.

Change:

<apex:selectlist value="{!A.Online_Courses__c}" />

To:

<apex:inputField value="{!A.Online_Courses__c}" />

Alternatively, if you still need to use an apex:selectList, you can use Apex Describe to get the values.

In the controller:

public List<SelectOptions> courseOptions { get; set; }
public String selectedCourse { get; set; }

public OnlineAdmission() {
    Schema.DescribeFieldResult dfr = Obj_A__c.Online_Courses__c.getDescribe();
    List<Schema.PicklistEntry> entries = dfr.getPicklistValues();

    List<SelectOption> coursesOptions = new List<SelectOption>();
    for (Schema.PicklistEntry entry : entries) {
        coursesOptions.add( new SelectOption(entry.getValue(), entry.getLabel()) );
    }
}

In the page:

<apex:selectList value="{!selectedCourse}" multiselect="false" size="1">
    <apex:selectOptions value="{!courseOptions"}/>
</apex:selectList>
| improve this answer | |
  • its something mistake in your code and i dont want with input field how i can get – Abdul Azeem Dec 15 '14 at 3:21
  • actually mistake is in VF page could u help me just check it once .... – Abdul Azeem Dec 15 '14 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.