function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sivasankari MuthuSivasankari Muthu 

Doubt:SOQL Query

Hi Everyone,
I have problem in soql query,
select a.Name,a.ID,ap.Product__c from account a,accproducts__c ap
where and'GenWatt Propane 1500kW'  and a.industry='banking';
error:Unknown error parsing query

Standard object:Account
Custom Object :accproducts__c

if anybody knows the solution please tell me.

Thanks & Regard,
M. Sivasankari
Sivasankari MuthuSivasankari Muthu
hi Amit Chaudhary,
Thankyou for your reply,
Again it shows the same error.

error:Unknown error parsing query

Amit Chaudhary 8Amit Chaudhary 8
Can you please post your full code
Deepak GulianDeepak Gulian
Can you please explain the relation b/w account and accproducts__c object?
Sivasankari MuthuSivasankari Muthu
hi Amit Chaudhary,
 For your query:
select a.Name,a.ID,ap.Product__c from account a,accproducts__c ap
where and'GenWatt Propane 1500kW'  and a.industry='banking';

In query editor it show an error as Unknown error parsing query 
In apex class it show an error as:
A driving SObject type has already been set, all other entity types in the FROM clause must be relationships to the initial object.  The driving object is Account.

My apex code:
Public with sharing class sfdctest{

 Public List<Account> acc{get;set;} 
 public String imageURL{get;set;}
 Public String searchStr{get;set;} 
  Public String searchStr1{get;set;}    
 public string productName{get;set;}
public List<selectoption> getIndustrynames()
    list<selectoption> options = new list<selectoption>();            
    Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
    list<schema.picklistentry> values = fieldResult.getPickListValues();               
    for (Schema.PicklistEntry a : values) 
        options.add(new SelectOption(a.getLabel(), a.getValue()));
    return options; 

public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    for(accproducts__c c : [select Product__c, from accproducts__c]){
        options.add(new SelectOption(c.Product__c,;
    return options;
 public  sfdctest()
    acc = New List<Account>();
    List< document > documentList=[select name from document where 
  Public void soslDemo_method(){
   if(searchStr.length() > 1){
       acc = [SELECT Name FROM Account WHERE Industry =:searchStr ]; /* This query produce the result based on the industry from account. i need result for both industry and product.*/
       if(acc.size() == 0){
           apexPages.addmessage(new apexpages.message(apexpages.severity.WARNING, 'Sorry, data not found'));
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please select the industry..'));
VFP code:
<apex:page sidebar="false" showheader="false" controller="sfdctest">
<apex:form >
<apex:pageMessages id="pId"/>
    <apex:image url="{!imageURL}">
      <apex:pageBlock title="Select a Industry" >
         <apex:outputLabel value="Inustry:"/>
          <apex:selectList value="{!searchStr}" size="1"> 
               <apex:selectOptions value="{!Industrynames}" />
          <apex:selectList size="1" value="{!productName}">
            <apex:selectOptions value="{!items}"/>

         <apex:commandButton value="Submit" action="{!soslDemo_method}" ReRender="pgId,pId" />
    <apex:pageBlock title="Customer details" id="pgId">
    <apex:pageblockTable value="{!acc}" var="account">
         <apex:column value="{!}"/>

Amit Chaudhary 8Amit Chaudhary 8
Try Query like below

SELECT Name,(select id,Product__c  from accproducts__r ) FROM Account WHERE Industry =:searchStr

Please replace "accproducts__c" with child relationship name
Sivasankari MuthuSivasankari Muthu
hi Deepak Gulian,
accproducts__c  object is intermediate between the account and product Standard object..

Sivasankari MuthuSivasankari Muthu
Hi Amit Chaudhary,
Your query:
SELECT Name,(select id,Product__c  from accproducts__r ) FROM Account WHERE Industry =:searchStr
In my case industry and product(Product__c) are input,

industry field=Account object(standard)
Product__c field =accproducts__c(custom object)

I tried below query  but doesnt work..
SELECT Name,(select id,Product__c  from accproducts__r where Product__c=:productName  ) FROM Account WHERE Industry =:searchStr
it takes only industry as input.


Rabindra BhowalRabindra Bhowal
I am tryig to get all the list of Account name from Account objects.

SELECT Name FROM Account;

but having following error message 
Unknown error parsing query