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
sekhar maramreddysekhar maramreddy 

to delete contact records through soql query

to delete contact records  through soql query
Yuvaraj mayilsamy 9Yuvaraj mayilsamy 9
Hi Sekhar,

 You can query for the contacts you want to delete and then you can perform a DML operation on those queried contacts to delete those.

Example : If I want to delete the contacts who are all from finance department below is the code.
 
list<contact> contactstodelete = [Select id from contact where department = 'Finance'];
delete contactstodelete;

Mark this as the best answer if it solves your question.

Yuvaraj 
Manj_SFDCManj_SFDC
in APex code you can use

List<Contact> contactsToDel = [SELECT Name FROM Contact WHERE LastName='Smith'];

if ( contactsToDel != null && !contactsToDel.isEmpty() ){
   try{
         delete contactsToDel;
  }
Catch(DmlException e){
// handle exception
}
}

in Developer console, Execute Ananymous Window you can use

delete [SELECT Name FROM Contact WHERE LastName='Smith']