Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //example of how to move opportunities from one account to another
- string accountId = '1MPt0000000CaRgGAK';
- list<SObject> updateList = new list<Opportunity>();
- for (Opportunity o : [select Id from Opportunity where AccountId =:accountId]){
- o.AccountId = '1MPt0000000CaRgGAK';
- updateList.add(o);
- }
- update updateList;
- //example of how to delete all opportunities on certain accounts and then delete the accounts
- //(can't delete the Accounts without deleting the Opptys first)
- //specifically this was used to find and delete certain accounts with open or won opportunities
- //if using in execute anonymous, the code to delete may have to be run multiple times if there is too much data
- //if refactored into a button, bulkification is suggested
- set<Id> targetAcctIds = new set<Id>();
- for(Account ogAcct : [select Id, from Account where Name like '%Canad%' or Name like '%canad%']);{
- targetAcctIds.add(ogAcct.Id);
- }
- list<Opportunity> targetOpptys = [select Id,StageName from Opportunity where AccountId in: targetAcctIds];
- system.debug('$$Opportunities size: '+targetOpptys.size());
- for (Opportunity o : [select Id,StageName from Opportunity where AccountId in: targetAcctIds]){
- o.StageName = 'Lost';
- targetOpptys.add(o);
- }
- delete targetOpptys;
- list<Account> targetAccounts = [select Id from Account where Id in:targetAcctIds];
- system.debug('$$targetAccounts size: '+ targetAccounts.size());
- delete targetAccounts;
- //example of how to delete all work orders on certain maintenance plans and then delete the maintenance plans (can't delete the MPs without deleting the WOs first)
- //specifically this was used to find and delete certain renewed maintenance plans
- //if using in execute anonymous, the code to delete the work orders will have to be run multiple times if there is too much data
- //if refactored into a button, bulkification is suggested.
- set<Id> targetMPIds = new set<Id>();
- for(MaintenancePlan ogMP : [select Id,MaintenancePlanNumber, Renewed_Maintenance_Plan__c from MaintenancePlan where MaintenancePlanNumber like '%0002' or MaintenancePlanNumber like '%0003' or MaintenancePlanNumber like '%0004' or MaintenancePlanNumber like '%0005' or MaintenancePlanNumber like '%0006' or MaintenancePlanNumber like '%0007' or MaintenancePlanNumber like '%0008' or MaintenancePlanNumber like '%0009' or MaintenancePlanNumber like '%0010' or MaintenancePlanNumber like '%0011' or MaintenancePlanNumber like '%0012' or MaintenancePlanNumber like '%0013' or MaintenancePlanNumber like '%0014' or MaintenancePlanNumber like '%0015' or MaintenancePlanNumber like '%0016' or MaintenancePlanNumber like '%0017' or MaintenancePlanNumber like '%0018']){
- targetMPIds.add(ogMP.Renewed_Maintenance_Plan__c);
- }
- list<WorkOrder> targetWorkOrders = [select Id,MaintenancePlanId from WorkOrder where MaintenancePlanId in: targetMPIds limit 1000];
- system.debug('$$target work orders size: '+targetWorkOrders.size());
- delete targetWorkOrders;
- list<MaintenancePlan> targetMaintenancePlans = [select Id from MaintenancePlan where Id in:targetMPIds];
- system.debug('$$targetMaintenancePlans size: '+targetMaintenancePlans.size());
- delete targetMaintenancePlans;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement