+ 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.

in APex code you can use

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

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

in Developer console, Execute Ananymous Window you can use

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