GithubHelp home page GithubHelp logo

sobjectdeletebatch's Introduction

SObjectDeleteBatch

Batch file that will delete object records based on dynamic SOQL passed in.

Ever been up against your data storage limits?

Ever wanted a quick way to delete a bunch of records?

Today’s your lucky day!

With just a couple of apex class files we can have a batch process that we can feed a SOQL query to and it will delete the records pulled up with the query. Really, it’s mainly one file. But we have to have a test file for it so we get good code coverage and feel confident about what it is doing.

Now, by default, this will only delete Tasks that are over 7 years old. But if you can craft a SOQL query that can get you the Id’s of a certain object’s records… well then, you’re in business.

With great power comes great responsibility. This isn’t a superpower, but it may feel like one. Be careful out there.

Test all your SOQL queries before you feed them to the batch. Make sure they only pull the records you want deleted.

Create New Files

There's only two, but do them in this order. Find them in the src folder of the repo.

  • SObjectDeleteBatch
  • SObjectDeleteBatchTest

How do I use this thing?

Let's consult the Book of Armaments. Chapter two, verses nine to twenty one.

This shall blow your records to bits... Then shalt thou count to two. No more, no less. Two shall be the number thou shalt count, and the number of thy counting shall be two.

Well, there's at least two that I'll go over for thou... err, you.

Using anonymous apex.

You can run this batch using the anonymous apex feature in different tools. Developer Console, Workbench, or VS Code to name a couple. Here’s the code:

String batchQuery = 'SELECT Id FROM Account WHERE Name = \'test account\'';
SObjectDeleteBatch deleteBatch = new SObjectDeleteBatch();
deleteBatch.batchQuery = batchQuery;
Id batchProcessId = Database.executeBatch(deleteBatch);

Using Batch Runner

There is a declarative way you could run the batch. Head over to my Batch Runner GitHub repo and check it out.

sobjectdeletebatch's People

Contributors

markhmorrison avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.