there is no soql command to delete rows. if your delete criteria is based on a where clause, you can do a query, then loop over the results to perform the delete.
The delete DML operation deletes one or more existing sObject records, such as individual accounts or contacts, from your organization’s data. delete is analogous to the DELETE statement in the Force.comWeb Services API. DML Statement Syntax as follows.
Thanks a lot for your suggestions. I tried the same with the following code :
List<suvra__marker__c> delmarker = new List<suvra__marker__c>();
delmarker=[select suvra__Street__c,suvra__City__c,suvra__State__c,suvra__Postal_Code__c, suvra__Country__c,suvra__Latitude__c,suvra__Longitude__c from suvra__marker__c where suvra__Street__c = null or suvra__City__c = null or suvra__State__c = null or suvra__Postal_Code__c = null or suvra__Record_Identifier__c = null or suvra__Latitude__c = null or suvra__Longitude__c = null];
delete delmarker;
But it is unable to delete the records from the custom table 'marker'. Kindly let me know if I'm missing anything here, or if there is any syntax error in the code.
List<suvra__marker__c> delmarker = new List<suvra__marker__c>();
delmarker=[select suvra__Street__c,suvra__City__c,suvra__State__c,suvra__Postal_Code__c, suvra__Country__c,suvra__Latitude__c,suvra__Longitude__c from suvra__marker__c where suvra__Street__c = null or suvra__City__c = null or suvra__State__c = null or suvra__Postal_Code__c = null or suvra__Record_Identifier__c = null or suvra__Latitude__c = null or suvra__Longitude__c = null];
delete [ select id from Object__c]; use it use proper condition in where clause, If you want to delete all records use above, but be sure what you are deleting
List<suvra__marker__c> delmarker = new List<suvra__marker__c>();
Just want to add that it is wasteful to declare the list and assign it to a new list as the SOQL will create a list and assign it to "delmarker" even if there are not any results.
After so many years, I don't think this question should still be showing up as "unanswered question". The answer was given and the if anyone stumbling upon this question has a similar problem, remember to add a debug message and check the size of the resulting object list..
ie.
List<Contact> contactResult = [SELECT Name FROM Contact WHERE LastName='CrazyLocoChicken'];
System.Debug('SOQL Returned ' + contactResult.size() + ' contacts');
if (contactResult.size() > 0){ delete contactResult; }
qr = binding.query(sql);
if (qr.size > 0)
{
bool bContinue = true;
while (bContinue)
{
List<string> list = new List<string>();
for (int i = 0; i < qr.records.Length; i++)
{
Gifts_and_Loans_of_Art__c sf_gift_objs = (Gifts_and_Loans_of_Art__c)qr.records[i];
list.Add(sf_gift_objs.Id);
}
string[] ids = list.ToArray();
// Max you can delete is 200 items at a time
for (int i = 0; i < ids.Length; i = i + 200)
{
string[] items = ids.Skip(i).Take(200).ToArray();
DeleteResult[] dr = binding.delete(items);
}
Console.WriteLine(ids.Length + " items deleted.");
Log.Information(ids.Length + " items deleted.");
//handle the loop + 1 problem by checking the most recent queryResult
if (qr.done)
bContinue = false;
else
qr = binding.queryMore(qr.queryLocator);
}
}
}
A single row delete is much simpler.
string[] ids = { myId };
DeleteResult[] del = binding.delete(ids);
The delete DML operation deletes one or more existing sObject records, such as individual accounts or contacts, from your organization’s data. delete is analogous to the DELETE statement in the Force.comWeb Services API.
DML Statement Syntax as follows.
delete sObject | Record.ID
delete sObject[] | LIST:ID[]
Hi All,
Thanks a lot for your suggestions. I tried the same with the following code :
List<suvra__marker__c> delmarker = new List<suvra__marker__c>();
delmarker=[select suvra__Street__c,suvra__City__c,suvra__State__c,suvra__Postal_Code__c,
suvra__Country__c,suvra__Latitude__c,suvra__Longitude__c from suvra__marker__c
where suvra__Street__c = null or
suvra__City__c = null or suvra__State__c = null or suvra__Postal_Code__c = null or
suvra__Record_Identifier__c = null or
suvra__Latitude__c = null or suvra__Longitude__c = null];
delete delmarker;
But it is unable to delete the records from the custom table 'marker'. Kindly let me know if I'm missing anything here, or if there is any syntax error in the code.
Thanks
List<suvra__marker__c> delmarker = new List<suvra__marker__c>();
delmarker=[select suvra__Street__c,suvra__City__c,suvra__State__c,suvra__Postal_Code__c,
suvra__Country__c,suvra__Latitude__c,suvra__Longitude__c from suvra__marker__c
where suvra__Street__c = null or
suvra__City__c = null or suvra__State__c = null or suvra__Postal_Code__c = null or
suvra__Record_Identifier__c = null or
suvra__Latitude__c = null or suvra__Longitude__c = null];
for(suvra__marker__c sm:delmarker)
delete sm;
can u try this..it might work :-?
Hi,
There is no error message or compilation error over here, but the records are not getting deleted from table.
Venkatesh, I tried your approach also, its giving the same problem.
This worked for me:
List<Object__c> objs = new List<Object__c>();
objs = [Select o.Field From Object__c o];
for (Object__c obj : objs){
delete obj;
}
I wanted to delete all rows in Object__c. This worked for me.
Cheers,
Filipe
Volunteer
Amnesty International Portugal
Was just looking up how to do this, it can be done even easier with just:
use it use proper condition in where clause, If you want to delete all records use above, but be sure what you are deleting
Just want to add that it is wasteful to declare the list and assign it to a new list as the SOQL will create a list and assign it to "delmarker" even if there are not any results.
After so many years, I don't think this question should still be showing up as "unanswered question". The answer was given and the if anyone stumbling upon this question has a similar problem, remember to add a debug message and check the size of the resulting object list..
ie.
List<Contact> contactResult = [SELECT Name FROM Contact WHERE LastName='CrazyLocoChicken'];
System.Debug('SOQL Returned ' + contactResult.size() + ' contacts');
if (contactResult.size() > 0){
delete contactResult;
}
A single row delete is much simpler.