How to write an apex class to delete records in a custom object in salesforce

how to write an apex class to delete records in a custom object in the sales department. let me know the solution

+5
source share
6 answers

Awaiting clarification of the question - see the DML removal operation . This will allow you to delete one or more existing sObject entries, including custom objects, from Apex.

You may need to verify that the sObject you are trying to delete has the delete property.


Foo__c ( "__c", , sObject), Apex :

List<Foo__c> existing = [SELECT Id From Foo__c];
delete existing;
+7

...

delete [select id from "Ur Obj Name"]; 

.....

+2

, ( ), :

"your_object_name"[] my=[select Id from "your_object_name"];
delete "your_object_name";
+1

, script:

"your_object_name"[] my=[select Id from "your_object_name"];
for("your_object_name" here: my)
{
        delete here;
}
0

for , 150 DML .

Remember that if your table contains more than 50,000 records, your query will not be executed. Therefore, you may need to save the records on the map when repeating the SOQL FOR loop. then outside the loop you can call delete on the map values.

-1
source

Account account = [SELECT Id From Account where Id = :id]; delete account;

-1
source

All Articles