Undeploy

Undeploy task

Objective

This task is able to undeploy code from Salesforce organization. To avoid dependency problems It truncates code and it deploys code truncated as first step and then It will try to delete all code from Salesforce organization according to local code.

Parameters

This class only have a parameter called excludes it can be used as task property or into your build script.

Interceptors by default

All code will be undeployed from SalesForce organization, truncating dependencies of next elements with its respective interceptors:

  1. Classes
    • truncateClasses
    • removeDeprecateAnnotation
  2. Objects
    • truncateFieldSets
    • truncateActionOverrides
    • truncateFormulas
    • truncateWebLinks
  3. Triggers
    • truncateTriggers
  4. Components
    • truncateComponents
  5. Pages
    • truncatePages
  6. Tabs
    • truncateTabs
  7. WorkFlows
    • truncateWorkflows

Note: Those interceptors by default are support on upload, deploy, update and undeploy tasks. You are able to create your custom interceptors using globalInterceptor or interceptor.

Undeploy task using interceptors

When the undeploy task is executed all interceptors by default will be executed.

Adding global interceptors

To add a new global interceptor you can use globalInterceptor method in the plugin extension “enforce”, it will be visible for all tasks that using the truncated process.


enforce {
    globalInterceptor('classes','printClassName', { classFile ->
        println classFile.name
    })
}


undeploy {
    interceptors = ['printClassName']
}

update {
    interceptors = ['printClassName']
}

Adding custom interceptor

To add a new interceptor you can use interceptor or firstInterceptor methods for each task where you want to add a new custom interceptor.

Adding a new anonymous interceptor, it will always be executed because it doesn’t have a specific name.

undeploy {
    interceptor('classes', { classFile ->
        println classFile.path
    })
}

Adding a new custom interceptor that will execute after of all interceptors on the classes for example.

undeploy {
    interceptor('classes','doLast', { classFile ->
        println classFile.path
    })
}

Adding a new custom interceptor that will execute before of all interceptors on the objects for example.

undeploy {
    firstInterceptor('objects', 'doFirst', { objectFile ->
        println objectFile.name 
    })
}

Note: Those interceptors have to be into build.gradle file.

Undeploy task using excludes parameter

This parameter can exclude files by:

Undeploy task help parameter

	$gradle truncate -Phelp

Examples:

Using excludes parameter:

To exclude all classes.

$ gradle undeploy -Pexcludes=classes
$ gradle undeploy -Pexcludes=classes/**
$ gradle undeploy -Pexcludes=classes/*.cls

To exclude all classes all objects and all triggers.

$ gradle undeploy -Pexcludes=classes,objects,triggers

To exclude the Class1.cls

$ gradle undeploy -Pexcludes=classes/Class1.cls

To exclude Class1.cls and Trigger1.cls

$ gradle undeploy -Pexcludes=classes/Class1.cls,triggers/Trigger1.trigger

To exclude all files that contain Account word with any extension and any folders.

$ gradle undeploy -Pexcludes=**\*Account*/**

To exclude all files with .cls extension.

$ gradle undeploy -Pexcludes=**/*.cls

Using interceptors by default:

command:

$ gradle undeploy

output:

    > gradle undeploy
    :undeploy
    ___________________________________________
          Username: john.doe@email.com
          Login type: login
    ___________________________________________

      [zip] Building zip: /user/build/deploy.zip
Starting undeploy...
[==================================================]   100%
All components truncated were successfully uploaded

      [zip] Building zip: /user/build/deploy.zip

[==================================================]   100%
The files were successfully deleted

    BUILD SUCCESSFUL