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
DEv NolanDEv Nolan 

How can you delete a specific record in a custom table with APEX based on a value in another field in another object?

???
ANUTEJANUTEJ (Salesforce Developers) 
Hi Nolan,

Generally to delete a specific record you can use a field that is unique to the record like the id to only delete a specific record, in case if you want to delete a list of records then you need to add a filter with a certain type to get only that list of records and then delete the list.

>> For deleting a specific record you can use:

objcet_name__c ob = [select id from objcet_name__c where id =: record_id]
delete ob;

>> For deleting a list of records where the field type value is certain value you can use the below snippet.

list<objcet_name__c> objlist=[select id from objcet_name__c where type__c ='type_value']
delete objlist;

Documentation >> https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_delete.htm

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.