You need to sign in to do that
Don't have an account?
System.QueryException: Didn't understand relationship 'accobj' in field path.
Hello All,
Good Morning, I'm getting below mentioned error while creating a VF page.
"System.QueryException: Didn't understand relationship 'accobj' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Class.OpportunitySearchController.search: line 38, column 1"
VF Page-
<apex:page standardController="Account" extensions="OpportunitySearchController" >
<style type="text/css">
body {background: #F3F3EC; padding-top: 15px}
</style>
<apex:form >
<apex:pageBlock title="Search For Opportunities With Keyword" id="block" mode="edit">
<apex:messages />
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Keyword</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!search}" status="status" reRender="resultsBlock"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionStatus id="status" startText="Searching ..Please wait"/>
<apex:pageBlockSection id="resultsBlock" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="srs" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column headerValue="Name">
<apex:outputLink value="/{!srs.Id}">{!srs.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!srs.StageName}"/>
<apex:column value="{!srs.Amount}"/>
<apex:column value="{!srs.CloseDate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Contrller ===>
public class OpportunitySearchController
{
private ApexPages.StandardController controller {get; set;}
private Account accobj;
public List<opportunity> searchResults {get;set;}
public String searchText {
get
{
if (searchText == null) searchText = 'Acme';
return searchText;
}
set;
}
public OpportunitySearchController(ApexPages.StandardController controller)
{
this.controller=controller;
this.accobj=(Account)controller.getRecord();
}
//fired when the search button is clicked
public PageReference search()
{
if(searchResults==null)
{
searchResults = new List<opportunity>();
}
else
{
searchResults.clear();
}
String qry = 'Select o.Id, o.Name, o.StageName, o.CloseDate, o.Amount from Opportunity o Where AccountId =\''+accobj.Id+'\' And accobj.Name LIKE \'%'+searchText+'%\' Order By o.Name';
searchResults =Database.query(qry);
return null;
}
}
Please helpme to get it corrected. Thanks for you all help and suggestions.
Presumably it is the "accobj.Name" in your search query . Did you mean o.name ?
String qry = 'Select o.Id, o.Name, o.StageName, o.CloseDate, o.Amount from Opportunity o Where AccountId =\''+accobj.Id+'\' And accobj.Name LIKE \'%'+searchText+'%\' Order By o.Name';
In you search query you are using soemthing called accobj.Name which is throwing the error.
I think the field name is wrong. Write the correct Opportunity field name.