9

When a controller has a method or a variable that is referenced in the VF page, and you remove or rename that element in both - page and controller, then when you click save, you get an error saying that the removed/renamed element is still referenced on the VF page, even though you are saving them both at the same time. Basically, SF checks the NEW version of the controller against the OLD version of the page.

When you work on these in the UI (development mode), then it's no big deal - you first delete the references in the page, save, then delete references in the controller. Or you could keep an empty method in the controller to satisfy this bug, create a new method with a different name, then delete the old empty method.

Now we are seeing this error during deploys (using jenkins/ant). The deploy process takes a while, as do the fixes to it, so this bug is a lot more annoying now.

Question - have you seen this issue, and how do you deal with it? Would you need to resort to changing your coding practices to keep all of the original methods and variables in the controller when you refactor, do the deploy, and then delete them from the controller before the next deploy? That seems a bit unclean.

2
  • 1
    Are both the new Page and Controller deploying within the same Transaction context? Commented Feb 13, 2014 at 15:46
  • Yes, both are being deployed at the same time. Commented Feb 13, 2014 at 18:52

5 Answers 5

8

Add a destructiveChangesPre.xml file to your deploy folder and put that VF Page in there and in your package.xml.

The destructiveChangesPre file will remove the VF Page before executing your deployment to get rid of the dependency. After that, the package.xml file will deploy the controller successfully, then deploy the updated VF page.

1
  • This should be the Answer. Cody, this helped me out and the issue was resolved very quickly. Thanks!
    – RC82
    Commented Apr 25, 2016 at 20:02
2

Salesforce keeps a meta table that tells it which functions are related to other pieces of code, etc. The controller is compiled first, since the page depends on the controller, and as it consults the meta table, it notices that an element that was used in the Visualforce page is now missing.

This halts the entire deployment instead of waiting to see if the element is no longer required. Pages that reference code will prevent changes or deletions to the code that would cause failures. Similarly, pages referenced in code can't be deleted without removing those references.

It would be ideal if they suspended meta table checks until the very end, as it often causes problems in other ways, too, such as trying to delete fields that will no longer be referenced in code, etc.

Multiple deployments are often the only solution. Our last internal release required a total of five deployments to move everything from Sandbox to production, with 30 minutes of unit tests for each phase.

1

I saw this error many times during development. As far as I know this occurs when you create a field value in your page and then declare, perform manipulations on that property in apex and then try to save both class and page at the same time. And yes this is the bug that salesforce need to fix in it's future releases as it is very annoying.

For anyone who want to replicate and see this error try creating a field on vf page(don't save), write some functionality for it in apex and then save.

How I dealt with it, clean all your changes refresh the browser and do it step by step. That's all I can suggest.

1

I'm unable to comment due to lack of reputation, but I would like to iterate that Cody Cusic has the right answer and verify that we have had this same issue many times.

This feature was added in Spring '15, as per here: https://help.salesforce.com/apex/HTViewSolution?id=000206765&language=en_US

The documentation for deleting files has been updated here: https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/daas_destructive_changes.htm

The Force.com Migration Tool Guide has been updated, Spring '16 version here: https://resources.docs.salesforce.com/sfdc/pdf/salesforce_migration_guide.pdf

For us, we will likely always copy the section of Pages and Components from our "package.xml" and copy them all to "destructiveChangesPre.xml". We didn't have to do anything special to get this to work... just added the file and started the deploy again. It is pretty ridiculous that we have to do this, as the deployment SHOULD validate the classes against the NEW versions of the pages/components anyway, but this is the option we've been given.

We recently had this in the case that a page controller was made to have a base-class. A property was moved to this base class as it was a more logical location. This resulted in the same errors saying that Visualforce pages were referencing the property (which still exists, just moved to the base class). We were deploying the base class, the main class, and the Visualforce pages in a single deployment so the error makes no sense.

Anyway, Cody Cusic's answer helped us out. Thanks Cody!

0

I have seen this issue a lot times and done the steps to overcome them (works for me many times)

This will mostly come due to the names matching to the Salesforce inbuilt methods or references

and if you really want to overcome means do as the steps as following:

1) Whenever you got this type of error, just don't waste time keep on saving the class and VF Page. Remember on which element the error is coming and Just re-login again.

2) After Login, First Open the Apex class related to the VF Page and Change the error coming name to the anything but not the previous (and the name must not be the Salesforce inbuilt names or referenced methods

3) After changing the Name of the Particular, Save Apex Class

4) Now open the VF Page and do the same thing as previous and Save it

5) Now the Error will not rise and the result will come

Example:

To save the record in VF Page, if you gave like action="{!Save}" (which is inbuilt salesforce action) and if you wrote the method as public string getSave(){**Some Code**}

then at this time, you will get an error because of the Name given as getSave.

Above is just an example, like these there are so many mismatching might occurs. So, follow the steps if you needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .