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,
 how to write a soql query 
we have two picklist. 
one is industry picklist-standard controller Account
another one is product(Product__c) picklist - custom object accproducts__c.
I want to pass these two picklist as a input to get a record 

I tried and doesn't work the 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


Thanks,
​M. Sivasankari
 
R Z KhanR Z Khan
Query for them as any regular field

WHERE Industry ='Your Industry' 
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can write this query as - 
select a.name, a.id, (SELECT ap.Product__c from  accproducts__r ap where ap.name='GenWatt Propane 1500kW') from account a where a.industry='banking'
Note : accproducts__r is the relationShip name. It may vary as I don't know the actual name. Yoy got to the lookup field anf look for child realtionship name. 

Thanks,
Sumit Kumar Singh 
Sivasankari MuthuSivasankari Muthu
Hi Sumit Kumar Singh,
Thanks.
After changed the accproduct__c to accproduct__r , it provide the result based on industry alone . I need both industry and product.



I attached the screenshot of my scenario .Please view it and  help me.
User-added image
Thanks in advance

Sivasankari.M
Sumit Kumar Singh 9Sumit Kumar Singh 9
Try, this one - 
select Product__c, Product__r.Name, Name, Product__r.Industry from accproducts__c where Product__r.Industry ='banking' AND  Name ='GenWatt Propane 1500kW'

Assuming 'Product__c' is the lookup field on 'Account produacts'
Pls, let me know if it helps you.
Sivasankari MuthuSivasankari Muthu
Hi Sumit,
Thanks.

As you said Product__c is the lookup field.Its right in my scenario.
But Industry is the Account standard field

so it shows the error as,
 
select Product__c, Product__c.Name, Name, Product__c.Industry
                   ^
ERROR at Row:1:Column:20
Didn't understand relationship 'Product__c' 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.
 Thanks
Sivasankari M
 
Sumit Kumar Singh 9Sumit Kumar Singh 9
My mistake.Try this one-
select Product__c, Product__r.Name, Name, Product__r.Industry from accproducts__c where Product__r.Industry ='banking' AND  Name ='GenWatt Propane 1500kW'
pls, let me know if it helps you.

Thanks,
sumit kumar singh
Sivasankari MuthuSivasankari Muthu
Hi 
Industry field is not in the accproducts__c(custom) object;
 accproducts__c Fields are:AccountId,ProductName;
Account(standard) Object Fields:Industry,AccountId, Account name.
Same error shown.

Thanks.
Sumit Kumar Singh 9Sumit Kumar Singh 9
I will try to resolve your probelm right now.
Sumit Kumar Singh 9Sumit Kumar Singh 9
Check the field level security for that fiels.
Sumit Kumar Singh 9Sumit Kumar Singh 9
What is the name of lookup field on 'accproducts__c' that is pointing to Account. I think that is worong. Query is correct.