5

i am using dynamic Visualforce component created in Apex

public with sharing class Sample3 {
    public Component.Flow.Interview flow{get;set;}
    public Sample3(){
    flow= new Component.Flow.Interview();
    flow.name='Calculator';     
    }
}

and VF page is

<apex:page controller="Sample3">
<apex:dynamicComponent componentValue="{!flow}"/>
</apex:page>

but when i open visualforce page its giving me error

Not Serializable: Component.flow.interview

As mentioned in comment i made a demo Class and VF Page

can anyone please tell How to resolve this issue ??

3
  • It would be helpful if you showed us the code for your entire VF page. There may be something else missing, like a reference to your controller.
    – crmprogdev
    Jul 12, 2014 at 13:38
  • i edited my question perhaps now you can respond :) Jul 12, 2014 at 13:48
  • Just like magic, see what happens when all the details are available? Keith C to the rescue with exactly the response you needed! :)
    – crmprogdev
    Jul 12, 2014 at 14:28

1 Answer 1

6

The (attempted) serialization of the not serializable component can be avoided by making the field transient:

public with sharing class Sample3 {
    private transient Component.Flow.Interview flow;
    public Component.Flow.Interview getFlow() {
        return flow;
    }
    public Sample3() {
        flow = new Component.Flow.Interview();
        flow.name = 'Calculator';
    }
}

or simpler still by not holding the value in a field at all:

public with sharing class Sample3 {
    public Component.Flow.Interview getFlow() {
        Component.Flow.Interview flow = new Component.Flow.Interview();
        flow.name = 'Calculator';
        return flow;
    }
    public Sample3() {
    }
}

For dynamic Apex components not including the component in the view state means the components do not work fully (see e.g. Field Values In Dynamic Component Not Retaining After Error); hopefully for your flow component there are no negative consequences.

You must log in to answer this question.

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