VF Page Updated to complete product 04/17/2017

<apex:page standardController="Position__c" extensions="Editpositions">  
    <apex:sectionHeader title="{!Position__c.Name}" subtitle="Edit Records"/>
    <apex:form >
        <apex:pageBlock title="Create and edit Job Positions">

            <apex:pageBlockButtons location="both">
                <apex:commandButton action="{!save}" value="Save Record"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            <apex:pageMessages />

            <apex:pageBlockSection title="Create New Position" columns="2">
                <apex:inputField value="{!Position__c.Name}"/>
                <apex:inputField value="{!Position__c.Responsibilities__c}"/>
                <apex:inputField value="{!Position__c.Job_Description__c}"/>
                <apex:inputField value="{!Position__c.Skills_Required__c}"/>
                <apex:inputField value="{!Position__c.Educational_Requirements__c}"/>
                <apex:inputField value="{!Position__c.Java__c}"/>
                <apex:inputField value="{!Position__c.Apex__c}"/>
                <apex:inputField value="{!Position__c.C__c}"/>
                <apex:inputField value="{!Position__c.Javascript__c}"/> 
                <apex:inputField value="{!Position__c.Travel_Required__c}"/>
                <apex:inputField value="{!Position__c.Location__c}"/>
                <apex:inputField value="{!Position__c.Open_Date__c}"/>
                <apex:inputField value="{!Position__c.Hire_By__c}"/>
                <apex:inputField value="{!Position__c.Min_Pay__c}"/>

                <apex:selectList multiselect="true" id="web" value="{!Website}" size="4" title="Website">
                    <apex:selectOptions value="{!site}"></apex:selectOptions>


public with sharing class Editpositions {

    public Position__c myPosition;
    public Position__c editpos {get;set;}
    public Job_Posting__c editpost {get;set;}
    public string[] Website {get;set;}

    public PageReference save() {

        return null;

    public Editpositions(ApexPages.StandardController controller) {
        this.editpos = (Position__c) controller.getRecord();
    public Position__c getPosition() {
        return myPosition;

    public List<selectOption> getsite(){
        List<selectOption> options = new List<selectOption>();  
        for (Employment_Website__c mySite : [SELECT Id, Name FROM Employment_Website__c]){
            options.add(new SelectOption(mySite.Id,mySite.Name));
        return options;

The only thing I think I forgot to do was to create a save function for the selectOption so when I click save it only saves the position but not the information from Employment website to the job posting which should show up on the position page. So I know I need to create job posting for each id using the individual id from list and the id of position or something along those lines. I know maybe I am complicating this too much for my level but this is the only way I can learn quickly so that I can go into the intermediate level developing trailhead on salesforce.

  • Ok, So I finally got a working VF page and Controller :). Honestly I am doing this without any background in coding period so please be nice to me haha. – Abdul Khan Apr 18 '17 at 1:20
  • 1
    If you would like to build up coding background look into the Trailhead platform. – Adrian Larson Apr 18 '17 at 2:08
  • I have definitely started on that @AdrianLarson I am just getting to the apex portion so far almost finished with administrator section and half way to apex . – Abdul Khan Apr 18 '17 at 3:14

Use This it Should work: -

Public List <SelectOption> getitems() {
    List<SelectOption>() options = new List<SelectOption>();
    options.add(new SelectOption('', '--None--'));
    for (Employment_Website__c mySite = [SELECT Id, Name FROM Employment_Website__c]){
        options.add(new SelectOption(mySite.Id,mySite.Name));
    return options;    
  • Since I am trying to retrieve 5 records from the Employment website to show up as a picklist the way we have stated do I need to really add the names of those records such as 'Craigslist', 'indeed', glassdoor,'salesforce' ? I have them in a list after the code you provided but I am just not sure that is how you do it. Other wise thank you showing love to a complete beginner..your help will not be wasted :) – Abdul Khan Apr 17 '17 at 1:13
  • If you want to show only any 5 records then put LIMIT 5 in your query,but if u want any specific value then you need to form your query properly – Avijit Das Apr 17 '17 at 2:58

This looks like it is not completed. You are missing the initial collection part 'List'.

<SelectOption> options = new List<SelectOption>();

Change that to:

List<SelectOption> options = new List<SelectOption>();

That should allow you to save the code and now you can test if passing the Select Options successfully works.

You should also check that you add a label to your options:

SelectOption option = new SelectOption(value, label);

In your code it will go on the lines of these:

public List <SelectOption> getitems() {

 List<SelectOption> options = new List<SelectOption>();

     Employment_Website__c mySite = [SELECT Id, Name
                                     FROM Employment_Website__c];      

     options.add(new SelectOption(mySite.Id, 'Id'));
     options.add(new SelectOption(mySite.Name, 'Name'));
     options.add(new SelectOption(mySite.Employment_Website__c, 'WebSite'));

     return options; 

That probably will work better. I haven't really tested this but I was able to save something similar using your logic. If you are getting any errors, please, tell us what errors you are getting.

Please, take a look at the SelecOption Class on this documents.

******** UPDATED ********

Yes, remove the () from the list collection at the beginning. Try to do the following to your code:

//options.add(new SelectOption(mySite.Employment_Website__c, 'WebSite'));

Make that line comment and save your code, then give it a try. Maybe you are using another field name for you "website"?


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.