You need to sign in to do that
Don't have an account?
Deleting an opportunity
Hi everyone,
I'm very new to the sforce API and was wondering if someone can provide me a with sample code on how to delete an opportunity. The example in the API manual is
private void deleteAccount()
{
// Delete call takes an string array of Ids as parameter
String[] IDs = new Sring[] {""};
// Invoke the delete call, saving the result in a DeleteResult object
DeleteResult[] deleteResults = binding.delete(IDs);
// Determine whether the delete call succeeded or failed
if (deleteResults[0].success)
{
// Delete operation succeeded
System.Diagnostics.Trace.WriteLine("Deleted: " + deleteResults[0].id);
}
else
{
// Delete operation failed
System.Diagnostics.Trace.WriteLine("Couldn't delete because: " +
deleteResults[0].errors[0].message);
}
}
What I don't understand here is how does it know it's an Opportunity ID and not Contact ID? Can someone please provide me with an example of how to delete an Opportunity ID=123456
Thank you
Maz.
Hi, maz00.
Take a look at name of procedure you mentioned in snippet: "DeleteAccount()". So it's stands for deleting accounts... But, actually, that procedure doesn't do anything since it creates empty IDs array. So the only way to perform deletion of any deletable object in SFDC I know is to retrieve somehow (via query or retrieve call) ids of those objects to be deleted and then (for example) to pass that array of IDs into procedure you mentioned. So it's gonna looks like:
private void deleteObjects(string[] IDs)
{
// Invoke the delete call, saving the result in a DeleteResult object
DeleteResult[] deleteResults = binding.delete(IDs);
// Determine whether the delete call succeeded or failed
if (deleteResults[0].success)
{
// Delete operation succeeded
System.Diagnostics.Trace.WriteLine("Deleted: " + deleteResults[0].id);
}
else
{
// Delete operation failed
System.Diagnostics.Trace.WriteLine("Couldn't delete because: " +
deleteResults[0].errors[0].message);
}
}
As for your question "how does it know it's an Opportunity ID and not Contact ID" - delete does know NOTHING about what to delete, it just get some ids and trying to delete corresponding objects.
Hope that makes senseMessage Edited by cmxint on 12-29-2004 11:36 PM
Thanks for the good advice cmxint.
I just wanted to add, the although it does not matter what the object is (the id uniquely "identifies" a particular record) you can derive the object's type by examining the first 3 characters of the id. These three characters or prefix indicates the type of object. These prefixes are defined for each object in the describeSObejct call results.
Cheers
Great. It worked. Thanks