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)


Thanks,
​M. Sivasankari
 
Siva SakthiSiva Sakthi
Hi,

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.. 
sandeep@Salesforcesandeep@Salesforce
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.

Thanks
Sandeep Singhal
http://www.codespokes.com/
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 ------------>'+acc.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

1) https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
2) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_lookup.htm
3) https://developer.salesforce.com/page/From_SQL_to_SOQL

Please let us know if this will help you