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 a.id=ap.account__c and ap.Product__r.name='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

Thanks,
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 a.id=:ap.account__c and ap.Product__r.name='GenWatt Propane 1500kW'  and a.industry='banking';

In query editor it show an error as Unknown error parsing query 
But,
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, Product__r.name from accproducts__c]){
        options.add(new SelectOption(c.Product__c, c.Product__r.name));
    }   
    return options;
}
 public  sfdctest()
  {
    acc = New List<Account>();
    imageURL='/servlet/servlet.FileDownload?file=';
    List< document > documentList=[select name from document where 
                                    Name='logo'];
    if(documentList.size()>0)
    {
      imageURL=imageURL+documentList[0].id;
    }
  }
 
  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'));
           return;
       }
   }
   else{
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please select the industry..'));
       return;
   }
  }
}
VFP code:
<apex:page sidebar="false" showheader="false" controller="sfdctest">
<apex:form >
<apex:pageMessages id="pId"/>
    <apex:image url="{!imageURL}">
    </apex:image>
      <apex:pageBlock title="Select a Industry" >
         <apex:outputLabel value="Inustry:"/>
          <apex:selectList value="{!searchStr}" size="1"> 
               <apex:selectOptions value="{!Industrynames}" />
          </apex:selectList>
          <apex:selectList size="1" value="{!productName}">
            <apex:selectOptions value="{!items}"/>
	</apex:selectList> 

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

Thanks,
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..


thanks,
 
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.

Thanks

 
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

Thanks