1

I have a below query in my controller class:

List<Skill_Review__c> results = [SELECT Id,Name,Skill__c,Level__c 
                                   FROM Skill_Review__c where Interview__c =:review.id ];

Skill_Review__c is a custom object and Skill_c and Level__c are lookup fields on this object. How can I get the Level__c and Skill__c from results list?

I tried like - results[0].Level__c ; but it says there no such expression.

VF pAge( Look for Level):

<apex:page standardController="Interview__c" extensions="SkillReviewExtension" showHeader="false">

  <apex:form >
       <apex:pageBlock title="Candidate Skill Evaluation" id="skills_list">

           <apex:pageBlockButtons location="top">
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Edit" action="{!Edit}"/>
           </apex:pageBlockButtons>

            <apex:pageBlockTable value="{! SkillReview }" var="ct" >      
               <apex:column value="{! ct.Skill__c}"/>
               <apex:column value="{! ct.Level__c}"/>
               <apex:column headerValue="Level">
                   <apex:selectList value="{!Level}" multiselect="false" size="1" rendered="{!isEditMode}">
                        <apex:selectOption itemValue="1" itemLabel="1"/>
                        <apex:selectOption itemValue="2" itemLabel="2"/>
                        <apex:selectOption itemValue="3" itemLabel="3"/>
                        <apex:selectOption itemValue="4" itemLabel="4"/>
                        <apex:selectOption itemValue="5" itemLabel="5"/>
                    </apex:selectList>
                    <apex:outputText value="{!Level}"/>       
               </apex:column>
                <apex:column headerValue="Description"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
   </apex:form>
</apex:page>

Controller:

public class SkillReviewExtension{

    private final Interview__c review;
    public  boolean isEditMode {get;private set;}
    public String Level{get;set;}
    List<SkillReview> skillReviewList;


     public SkillReviewExtension(ApexPages.StandardController stdController) {
        this.review= (Interview__c)stdController.getRecord();
        }

    public List<Skill_Review__c> getSkillReview() {
        skillReviewList=new List<skillReview>();

        List<Skill_Review__c> results = [SELECT Id,Name,Skill__c,Level__c FROM Skill_Review__c where Interview__c =:review.id ];

        results.size();
        //skillReviewList.skillReview[0]=results.clone();
        return results;    
    }


    public PageReference save(){
        isEditMode=false;
        return null;
    }

    public PageReference edit(){
        isEditMode=true;
        return null;
    }  





}
8
  • Are you assigning it to any variable? can you post that part. What you have should work. i would put in a system.debug to see if the value is there or not
    – Prady
    Commented Mar 16, 2016 at 17:44
  • I want to assign it to a String Level variable in my Visual force page. Please see my Visual force page in the edit. Please see the level there.
    – SfdcBat
    Commented Mar 16, 2016 at 17:45
  • I would like to assign the Level variable from VF page to level__c lookup field. The Level is a way for user to input the value and I would store the user input value to Level__c and update the record.
    – SfdcBat
    Commented Mar 16, 2016 at 17:48
  • if you want to just assign the value of Level__c into string variable level then use Level = results[0].level__c. Note this would give you an id of the level record as you had mentioned these were lookup fields.
    – Prady
    Commented Mar 16, 2016 at 17:52
  • 2
    All lookup fields will store 18 character recordids so when you try to update the value 1 or 2 or into that field it will throw you an error
    – Prady
    Commented Mar 16, 2016 at 18:05

1 Answer 1

0

one way is that you have the field as a lookup field. Remove the selectList and use <apex:inputfield value = "{! ct.Level__c}"/>.

<apex:pageBlockTable value="{! SkillReview }" var="ct" >      
               <apex:column value="{! ct.Skill__c}"/>
               <apex:column value="{! ct.Level__c}"/>
               <apex:column headerValue="Level">
                    <apex:inputfield value = "{! ct.Level__c}"/>.
               </apex:column>
                <apex:column headerValue="Description"/>
            </apex:pageBlockTable>
        </apex:pageBlock>

If you really want to use the selectList then in your controller query all your available levels and add them into a selectoption.

   <apex:selectList value="{!ct.Level__c}" size="1" multiselect="false"  >
     <apex:selectOptions value="{!ListOfLevels}" />
   </apex:selectList>

Your controller would have

public List<SelectOption> getListOfLevels()
{
  List<Level__c> levels = [select id ,name from Level__c] ;
  List<SelectOption> ListOfLevels= new List<SelectOption>();

               ListOfLevels.add(new SelectOption( ' ' ,'---Select---'));

               for(Level__c u : levels )
               {
                          ListOfLevels.add(new SelectOption(u.Id , u.Name));
               }

              retrun ListOfLevels;

    }

I havent tested this code for any errors, but in general this approach should work

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .