You need to sign in to do that
Don't have an account?
bpl3792
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; } }
I figured it out...All I needed to do was add my calls in the pagereference
All I needed for the visualforce page was this.
Thanks for your help!
All Answers
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:
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....
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.
Have you added debug to your controller to check that the method that executes the soql is being called?
I figured it out...All I needed to do was add my calls in the pagereference
All I needed for the visualforce page was this.
Thanks for your help!