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
sanjusfdcsanjusfdc 

Delete leads for particular user

Hello all,
How we can delete all Leads in our database that have the Lead Owner 'xyz'. I tried based on ownerId but it didnt work. can't we lookup field(ownerId) in where condition under Query.
Select id from Lead where  OwnerId = '2F0050Y000000ZAbc'

Please guide me if I am wrong.
Thanks in advance.
Best Answer chosen by sanjusfdc
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sanju,

User Id will start with 005 and you need to remove the 2F from the userId.

try with below in developer console, announumos window.
List<Lead> deleteleads = [select id from lead where ownerId='0050Y000000ZAbc'];

Delete deleteleads;

If this helps, Please mark it as best answer.

Thanks!!