You need to sign in to do that
Don't have an account?
Lakshmi S
soql query for fetching records from Account not related to Contact object?
Hi Dev's,
SOQL query for fetching records from Account not related to Contact object?(Only account records, which are not related to contact)?
Regards
Lakshmi
Thanks in advance..
SOQL query for fetching records from Account not related to Contact object?(Only account records, which are not related to contact)?
Regards
Lakshmi
Thanks in advance..
Please check below post to learn about SOQL
1) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm
2) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm
3) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding
4) https://trailhead.salesforce.com/en/apex_database/apex_database_soql
5) https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
Let us know if this will help you
All Answers
List<Id> acc_ids = new List<Id>();
for(Contact c : con){
if( c.account.id != null)
{
acc_ids.add(c.account.id);
}
}
List<Account> list_accounts = [Select id,name from account where id not in :acc_ids];
system.debug(list_accounts);
1.This query for without relationship with contact ,that means only account records.
list<account> acc = [select id,name from account where Id not in(select accountid from contact)];
system.debug('========='+acc.size());
2.This query for relationship between contact and account records.
list<account> acc2 = [select id,name from account where Id in(select accountid from contact)];
system.debug('========='+acc2.size());
Please check below post to learn about SOQL
1) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm
2) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm
3) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding
4) https://trailhead.salesforce.com/en/apex_database/apex_database_soql
5) https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
Let us know if this will help you