You need to sign in to do that
Don't have an account?
ZurMiles
Delete Account if ....
Hello all,
I'm trying to look for the best way to delete an Account if there is not Opportunies, Contacts, Tasks or Events active on that Account. Wat would be the best a more simple way to wirte this on Apex?
Thanks on advance.
ZurMiles
I would suggest you look at: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem as well as other examples on the forum where folks have suggested simple apex schedulable classes - then adapt to your use case
see also:
All Answers
ZurMiles
Sounds like you are trying to delete 'dead' accounts automatically?
Automatic Options:
1. Use Scheduled Apex and a schedulable class that runs through your database on some cycle looking for qualifying accounts and then using APEX DML to delete them (ideally, logging its actions). This 'qualifying' code could do
select id, (select id from Contacts limit 1), (select id from Opportunities limit 1), ... from Account
and then inspect the size of the relationships to see if children records are present
Manual Options:
1. Use tools like Mass Delete Anything or Data Loader. For these to work, you'll need to have fields in Account that unambigously tell you that it is safe to delete. Count of Opporutnities is easy with a RSF field, other child SObjects would require triggers that ask the Account to maintain a count of the child records
Hello Eric,
Do you think you could put a short scrip to explain that?
I will really appreciate it if you could.
ZurMiles
I would suggest you look at: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem as well as other examples on the forum where folks have suggested simple apex schedulable classes - then adapt to your use case
see also:
Thanks for those links, they are definitely a good approach.
Here is a piece of code from someone that was working in my company. We have no developers right now and my level on APEX is not even close to this. The problem is that this code is not working for some reason and I can't figure out why. I was thinking on writing something my self but I still need to understand better apex before building something that will delete our accounts in case they are part of a specify criteria.
Can someone let me know if there is something wrong on this script?
Thanks in advance!
zurMiles
This code looks like it might be associated with an override of the Delete button for a single Account
It will either
a) delete the Account
b) Change the account status to Deactivated (and not delete)
c) Issue an error message saying action can't be done
This is not a solution for a scheduled job that auto-deletes qualifying accounts
Thanks Eric,
I have been looking to our Accounts delete button and it use the default SFDC. I think that probably I need to create a new scrip and use the schedule that you was mentioning.
Thanks again.
I will try and see how far can I go !!