Slaesforce FAQ

how to delete classes from production salesforce

by Winifred Russel DVM Published 2 years ago Updated 2 years ago
image

Delete class from production

  1. Force.com IDE should be installed.
  2. Connect to the Sandbox Instance using the IDE and find the class or trigger that you want to delete.
  3. Open the matching .xml file, and change the Status XML tag from Active to Deleted.
  4. Or to disable the trigger change it to Inactive. Note: Apex class Status can only be changed to "Active" or...
  5. Save the file.

Remove Apex Class or Trigger
  1. Install Ant Migration Tool.
  2. Connect to the Production Instance and find the class or trigger that you want to delete.
  3. Retrieve the matching class or trigger, and change the Status XML tag from Active to Deleted.
  4. Or to disable the trigger change it to Inactive. ...
  5. Save the file.

Full Answer

How do I delete all classes in a Salesforce Org?

Let’s say that you have a Salesforce production org that has two Apex classes that need to be deleted. To achieve this via Workbench, create a folder on your desktop. I will call my folder ‘deleteClasses’. Then go to Notepad (or another text editor) and copy and paste the below and save as the file with ‘package.xml’ and ‘All files (*.*)’.

Can I delete an apex class from a Salesforce production?

The Force.com migration tool (ANT) can take some time to learn how to use properly. Apex classes and triggers cannot be deleted from a Salesforce production declaratively, unlike in sandbox orgs. This is because security for Apex in Salesforce production orgs is greatly increased.

How do I delete a class in production?

You cannot delete a class in production directly. You will need delete the class from your sandbox and then deploy the deletions to your production org. When you deploy from sandbox to production, the missing classes will come up in red and you can choose to deploy these deletions to Production.

How to delete a class from the force server?

1) From Force.com IDE, select the class that you want to delete (Look for .xml extension ) 2) Open that .xml version of your class and change the Status tag to Deleted. 3) Right click and save the file. 4) Now select "SRC" folder and right click--->Select Force.com---> select Deploy to server

image

Can we delete class from production Salesforce?

You cannot delete a class in production directly. You will need delete the class from your sandbox and then deploy the deletions to your production org.

How do I delete a class in Salesforce?

1. Probably the simplest way to delete / disable is to connect to your Salesforce production org from VS Code download the apex class / trigger, change the status of the Apex class / trigger to “Deleted” or “Inactive” in the class/trigger XML file and save.

How do you delete Apex class from production using VS code?

Visual Studio Code (VS Code) To do the delete we need to do the following steps: Find the class or apex trigger we need to remove and update the metadata status to be “Deleted”. Run the sfdx force deploy command with all of the classes/triggers separated by “,” using the terminal.

How do I delete a component from production in Salesforce?

To delete components, perform a deployment with the deploy() call by using a destructive changes manifest file that lists the components to remove from your organization. You can perform a deployment that only deletes components, or a deployment that deletes and adds components.

How do I deactivate a class?

Delete a classGo to classroom.google.com and click Sign In. Sign in with your Google Account. ... At the top, click Menu .Scroll down and click Archived classes. Note: If you haven't archived any classes, this option won't be in the menu.​On the class card, click More. Delete.Click Delete to confirm.

How do I edit Apex class in production?

No, it is not possible to edit apex classes and triggers directly in production environment. It needs to be done first in Developer edition or testing org or in Sandbox org. Then, to deploy it in production, a user with Author Apex permission must deploy the triggers and classes using deployment tools.

How do I delete a class in dev console?

Follow the below steps to do that in production instances,Create new project in eclipse and download all the source code from production.Open the meta-data of the file you want to delete in production and change the status to Delete.Click save to server to delete the class in the production.

Can we deactivate trigger in production?

In general, triggers are not editable once deployed to production org. However, in certain circumstances there might be a need to disable triggers in production. Note: Consider the consequences of disabling a trigger in the production environment during work hours.

How do you deploy an Apex class to production?

It's very simple no need of eclipse. Create an outbound changeset add your class that you modified and upload it to the production and then log into production search for inbound changeset you will get your changeset deploy it by selecting run the local test.

How do I delete a test class from production in Salesforce?

Remove Apex Class or TriggerInstall Ant Migration Tool.Connect to the Production Instance and find the class or trigger that you want to delete.Retrieve the matching class or trigger, and change the Status XML tag from Active to Deleted.Or to disable the trigger change it to Inactive. ... Save the file.More items...

Can we delete trigger in production Salesforce?

- Connect to the Sandbox Instance using the IDE and find the class or trigger that you want to delete. - Open the matching . xml file change the Status XML tag from "Active" to "Deleted" if you want to remove the trigger or class, or to "Inactive" if you want to disable the trigger.

Where are unused Apex classes in Salesforce?

The another solution is by using the "Apex code analysis tool", this is a third party tool, you can run this tool whenever you are creating a new apex class. This will help you to find the unused code.

The Problem

The most common approach to deleting Apex classes and triggers in a Salesforce production environment is to leverage either the Force.com IDE or the Fo r ce.com Migration tool. These tools have a number of downsides, namely.

The Solution

Let’s say that you have a Salesforce production org that has two Apex classes that need to be deleted.

What is SFDX CLI?

The SFDX CLI is a command-line tool that was first introduced for working with scratch orgs. However, further updates have enabled it to work with sandboxes and production orgs.

Can you reset your Salesforce security token?

Replace <password><security token> with your password and security token, one following the other with no spaces in between. If you do not know your security token, you can reset it from your personal settings in Salesforce.

Force.com Migration Tool (ANT)

The Force.com Migration Tool uses the Apache Ant tool to do deployments (additions, updates, deletes). Additions or updates should be included in the package.xml file and removals need to be done in the destructiveChanges.xml file.

Workbench

If you are infrequently doing deletions or deployments through the Force.com migration tool, Workbench is a better solution. It doesn’t require learning the terminal or learning how to use the ANT. The file structure and files are identical because it is basically running the same process.

Wrapping It Up

In this blog post, we’ve covered how to do deletions of apex classes and apex triggers from a production Salesforce org using Force.com Migration Tool (ANT), Visual Studio Code, Workbench, and even the deprecated Force.com IDE.

image

Why Should I Care?

Deleting Production Code with destructiveChanges.xml

  • The only way to delete classes from a production org is via the metadata API. Fortunately, there are two tools that we can use to easily interface with it. The SFDX CLIis a command-line tool that was first introduced for working with scratch orgs. However, further updates have enabled it to work with sandboxes and production orgs. While documentati...
See more on linkedin.com

Getting Started

  • For the sake of not sending you running around the internet gathering tools, I've compiled a little archive that includes Ant, the Ant Migration Tool, a sample project to remove a file (including destructiveChanges.xml), and scripts to use both Ant or the SFDX CLI. Download the tools here. If you wish to use SFDX, you can download it here. If you would rather use Ant, please make sure t…
See more on linkedin.com

Set Your Credentials

  • Option 1: SFDX CLI
    Inside the folder you extracted, you will find a file called sfdxLogin.bat. For Windwos users, this will execute the SFDX command that authenticates an org on your computer: If you're on any other operating system, you will have to type this in a terminal window (in any folder you'd like). Make …
  • Option 2: Ant Migration Tool
    In the folder you extracted, find the file build.properties. This is where we set our login credentials so that the migration tool removes files from the correctorg, and some poor soul three thousand miles away doesn't wake up to discover theirs completely broken. In the file, find the following s…
See more on linkedin.com

Select Components to Delete

  • Next, find the directory called remove, which contains a file called destructiveChanges.xml. Inside this file you will find this: This tells the system which components you want to delete. In this sample, it will attempt to delete an Apex class called Testing. Makes sense, right? Unless you're one of those people who wins the lottory every week, chances are the class you're trying to delet…
See more on linkedin.com

Final Preperation

  • Before you actually perform the deletion, ask yourself if you're certain this is what you want to do. There is no way to retrieve this data beyond this point. You may want to make a backup, check that nothing else uses the file, consult with others... or maybe you're the type who rolls the dice - well let's roll! Is this a good outcome? What game are we even playing here? Stock photos make …
See more on linkedin.com

Execute The Deletion

  • The last step is to execute the ant migration tool. For Windows users, I've preparedsome batch scripts to handle things depending on your selected method. If you're on a different operating system, you will need to run some commands in the terminal window.
See more on linkedin.com

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9