+ Start a Discussion
bpl3792bpl3792 

Need help displaying SOQL data in a visualforce page from a controller

I'm trying to run a SOQL query to pull monitor information from our asset object. I'm new to salesforce so I'm not sure if my understanding is quite correct but if I could be pointed in the right direction that would be great.

 

The user enters a serial number to search for here

 

<apex:page controller="AssetManInputController">
<apex:form >
    <apex:pageBlock title="Monitor Search">
    <apex:outputLabel value="Serial Number" />:
    <apex:inputText value="{!searchString}" />
    <apex:facet name="footer">
        <apex:outputPanel >
            <apex:commandButton action="{!step2}" value="Search" />
        </apex:outputPanel>
    </apex:facet>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

Once it's completed it redirects to this page to display the information but I get the error "Unknown property 'AssetManInputController.Acquistion_Date__c" 

 

<apex:page controller="AssetManInputController">
 
<apex:form >
    <apex:outputLabel value="Serial Number" />: 
    <apex:outputLabel value="{!SearchString}" /><br/>
    <apex:outputLabel value="Acquistion_Date__c"  for="{!Acquistion_Date__c}" /><br/>
    <apex:outputLabel value="Monitor_Manufacturer__c" for="{!Monitor_Manufacturer__c}" /><br/>
    <apex:outputLabel value="Monitor_Model__c" for="{!Monitor_Model__c}" /><br/>
</apex:form>


</apex:page>

 

Here's the soql query 

 

global with sharing class AssetManController 
{ 
 public IT_Asset__c ITO2 {get;set;}
 private String Serial,
                Manufacturer,
                Model;
 
       
      public IT_Asset__c getMonitorInfo(String Serial){
           IT_Asset__c c = [SELECT Acquistion_Date__c, Monitor_Manufacturer__c, Monitor_Model__c from IT_Asset__c WHERE Serial_Number__c = :Serial];
           IT_Asset__c l = new IT_Asset__c(Acquistion_Date__c=c.Acquistion_Date__c, Monitor_Manufacturer__c=c.Monitor_Manufacturer__c, Monitor_Model__c=c.Monitor_Model__c);
           return l;
      }
      
}

 The controller

public class AssetManInputController 
{

   private string Serial;
   public IT_Asset__c ITASSET {get; set;}
   AssetManController assetman = new AssetManController();
     
    public void setSearchString(String val) 
    {
        Serial = val;
    }

    public String getSearchString() 
    {
       return Serial;
    }

    public IT_Asset__c getAssets() 
    {
    	
        IT_Asset__c assets=assetman.getMonitorInfo(Serial);
        return assets;
    }

    public PageReference step2() 
    {
        return Page.assetman;
    }

}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bpl3792bpl3792

I figured it out...All I needed to do was add my calls in the pagereference

    public PageReference step2() 
    {
        getMonitorInfo(Serial);
        getMonitorModel();
        getMonitorManufacturer();
        return Page.assetman;
    }

 All I needed for the visualforce page was this.

    <apex:outputLabel value="{!MonitorManufacturer}" /><br/>
    <apex:outputLabel value="{!MonitorModel}" /><br/>

 Thanks for your help!

All Answers

bob_buzzardbob_buzzard

You need to prefix the fields with the name of the sobject property from the controller, which is ITASSET.  However, I think your markup is a bit confused, as you are using merge fields in the for attribute of the label, which should be the id of the component the label is applied to.

 

If you are trying to output a label and value, I'd suggest you need something like:

 

<apex:form >
    <apex:outputLabel value="Serial Number" />: 
    <apex:outputLabel value="{!SearchString}" /><br/>
    <apex:outputLabel value="Acquistion_Date__c"  for="acdate" />
 <apex:outputField id="acdate"value="{!ITASSET.Acquisition_Date__c}" /><br/>
.... </apex:form>

 

 

 

 

 

 

kiranmutturukiranmutturu

there for is "The ID of the component with which the label should be associated. When the label is in focus, the component specified by this attribute is also in focus".  its a string not a merge field that have to give there...

i didnt understand y u wrote that global class again.. you can do query in the public class its self....

 

its better to start working with fundamentals or practise workbook tutorials....

bpl3792bpl3792

You're right. It was an example I copied and tweaked for my purposes so I could better understand what was going on. I made the changes as you recommended but it doesn't return any data.

 

Public class AssetManController 
{ 

   private string Serial,
                  MonitorMFG,
                  MonitorModel;
   public IT_Asset__c ITASSET {get; set;}
 
     
    public void setSearchString(String val) 
    {
        Serial = val;
    }

    public String getSearchString() 
    {
       return Serial;
    }
    
    public IT_Asset__c getMonitorInfo(String Serial){
           IT_Asset__c c = [SELECT Acquistion_Date__c, Monitor_Manufacturer__c, Monitor_Model__c from IT_Asset__c WHERE Serial_Number__c = :Serial];
           IT_Asset__c l = new IT_Asset__c(Acquistion_Date__c=c.Acquistion_Date__c, Monitor_Manufacturer__c=c.Monitor_Manufacturer__c, Monitor_Model__c=c.Monitor_Model__c);
           IT_Asset__c assets=l;
           MonitorMFG=assets.Monitor_Manufacturer__c;
           MonitorModel=assets.Monitor_Model__c;
           return assets;
    }
    
    public string getMonitorManufacturer(){
        
        return MonitorMFG;
    }
    
       
    public string getMonitorModel(){
        return MonitorModel;
    }

    public PageReference step2() 
    {
        return Page.assetman;
    }

}
   

 

    <apex:outputLabel value="{!MonitorManufacturer}" for="MonitorMFG" />
    <apex:outputField id="MonitorMFG" value="{!ITASSET.Monitor_Manufacturer__c}" /><br/>

 

bob_buzzardbob_buzzard

Have you added debug to your controller to check that the method that executes the soql is being called?

 

bpl3792bpl3792

I figured it out...All I needed to do was add my calls in the pagereference

    public PageReference step2() 
    {
        getMonitorInfo(Serial);
        getMonitorModel();
        getMonitorManufacturer();
        return Page.assetman;
    }

 All I needed for the visualforce page was this.

    <apex:outputLabel value="{!MonitorManufacturer}" /><br/>
    <apex:outputLabel value="{!MonitorModel}" /><br/>

 Thanks for your help!

This was selected as the best answer
David Roberts 4David Roberts 4
This is a great thread but is advanced for me. Where can I find a simple example of a VisualForce page returning the result of a query?