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 

Problem in soql Query

Hi EveryOne,
 how to write a soql query 
I have two picklist. 
one is industry picklist- Account (standard Object)
another one is product(Product__c) picklist -  accproducts__c (custom object)
I want to pass these two picklist as a input to get a record .

I attached the screenshot of my scenario .Please view it and  help me.
User-added image
In Expected Result : 
Account Id ,Industry & Account name - Account (Standard object)
Product name - accproduct__c (Custom Object)

​M. Sivasankari
Siva SakthiSiva Sakthi

Do you have a Standard Object Account look up field in your Custom Object accproduct__c. If you have therelationship between two object means easly get the result. Other wise using wrapper class to get different object values and show into the table.. 
Here I would like to mention below query:
List<Account> ListofAccounts = new List<Account>();

// Here I have considered that accproducts__r  is child relationship name of Accproducts__c object under Account object.

ListofAccounts = [select id,Industry,(select id from accproducts__r where Product__c = 'FGH') from Account where industry = 'Banking'];

You may reac me out in case of further query.

Sandeep Singhal
Amit Chaudhary 8Amit Chaudhary 8
Try below code. That will help you
List<account> lstAccount = [ select name, id,industry , (SELECT Product__c from  accproducts__r ) from account ];

For( Account acc : lstAccount )
	System.debug('-------Account Industry ------------>'+acc.industry );
	System.debug('-------Account Name ------------>' );
	List<accproduct__c> lstAccProd = acc.accproducts__r ;
	for( accproduct__c accProd : lstAccProd )
		System.debug('-------Account Product ------------>'+accProd.Product__c );
To understand the relationship between to object please check below post. I hope that will help you


Please let us know if this will help you