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
ezhil_kezhil_k 

Soql query

I want to delete an account,i know only the contact name.I need to find in which account the contact is present, and need to delete the account. what is the Soql query for this?

Best Answer chosen by Admin (Salesforce Developers) 
Sandeep001Sandeep001
Account acc = [SELECT Id FROM Account WHERE Id IN (SELECT AccountId FROM Contact where Name='Contact Name')];

delete acc;

 

All Answers

AmitSahuAmitSahu
Select id, accountid from contact where name='contact name'
Query for the account id and delete it.

Not sure got your question wrong.
Sandeep001Sandeep001
Account acc = [SELECT Id FROM Account WHERE Id IN (SELECT AccountId FROM Contact where Name='Contact Name')];

delete acc;

 

This was selected as the best answer