10

I have 4 classes which are dependent on each other and i am always running into circular dependencies which is causing the code not to compile. I have a controller which has a reference to a viewstatecontroller class which holds page data. I have a couple of processor classes which have a base called processor base. The processor class would handle page on load, prev and next methods. What is the sequence of flow in which salesforce compiles the classes?

Interface

public interface AB_Processor_INF
{
     void setViewstateController(AB_ViewstateController controller);  
     PageReference page_next();
     PageReference page_back();
     void setPrimaryController(CTRL_AB_Prime pc);
     void page_load();
}

Controller

public with sharing class CTRL_AB_Prime {

 public CTRL_AB_Prime()
    { 

        viewstateController = AB_ViewstateController.getInstance();
        serviceController = AB_ServiceController.getInstance();
        languageCode = 'EN';


    }
}

Each page would call a processor class to handle page load, prev and next events

Processor class

public with sharing abstract class Proc_AB_Base implements AB_Processor_INF
{  

    public CTRL_AB_Prime primaryController;


    public void setPrimaryController(CTRL_AB_Prime pc)
    {
        primaryController = pc;
    }

}

Page specific processor class below..

public with sharing class Proc_ABOAQ extends Proc_AB_Base {
    private static final Proc_ABOAQ instance  = new Proc_ABOAQ();

    private Proc_ABOAQ()
    {
    }

    public static Proc_ABOAQ getInstance()
    {
        return instance;
    }

    public override PageReference page_back_processing()
    {
         return null;
    }

    public override PageReference page_next_processing()
    {
    }
}   
2
  • I would save the components in the order you have listed them. You can turn off Build Automatically from Project Properties and build each class using Ctrl + B (Assume your view state controller compiles okay) Apr 11, 2013 at 20:11
  • @MarkPond Is there any document to show how salesforce looks at classes to compile? Apr 12, 2013 at 3:04

1 Answer 1

3

It appears to me that you're asking two distinct questions.

I did some research this morning and couldn't find a definitive document to answer your question with respect to load/flow sequence on page load. I only found compile order references that were with respect to managed packages. That doesn't seem to apply to your question.

The closest references I could seem to find all referred to the view state and how to use the Development mode footer. One related reference was Order of Execution in a Visual Force Page which still didn't seem to apply to the real gist of your question. In the viewstate, you'll see which controllers have loaded, the memory they're using, and based on the order they appear, it may or may not imply the order in which they were loaded. I couldn't find anything which told me that. However, checking the log in the Developer Console would potentially seem to answer that question.

Your primary question seems to be, "how do I resolve circular dependencies with multiple controllers and visualforce pages?" I've encountered this problem myself, especially when working with different versions of the same controller. The solution I found the most helpful was to use a template for the page. That way, I only needed to change the reference to the primary controller in one place. If you're using different versions of the other controllers, whether they're referenced separately or in a primary custom controller that you can version, you may simply need to create more than one template to accommodate their implementation.

That's what has worked for me as well as others I've seen blog on the subject. Its a practice that greatly simplifies keeping track of these kinds of dependencies. Others use it for things like revisions to CSS.

2
  • Thanks for your help. Do you have an ant script which compiles classes in a certain order which you use for deployment? Buyan May 13, 2013 at 22:17
  • Sorry buyan I don't. If I did, you'd be more than welcome to it. You might check the ant download site for scripts or ask in chat.
    – crmprogdev
    May 14, 2013 at 12:29

You must log in to answer this question.

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