function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
h20riderh20rider 

IsPostBack Equivalent

Is there a IsPostBack Equivalent in SFDC.  Or a way to get the request type (post,get, etc)

sfdcfoxsfdcfox
What's the use case? There's no need to determine if a page is post-back in Visualforce if it's written properly.
h20riderh20rider

Maybe I am.  I have a component that I want to set up the variables and not run every time

Suggestions

sfdcfoxsfdcfox

There are two approaches I've used that covers 100% of use cases.

 

1) Constructor

 

You can initialize data using the constructor for the controller, which won't be called during a postback.

 

Example:

 

<apex:component controller="compCont">
    ...
</apex:component>
public with sharing class compCont {
    public compCont() {
        x = 15;
        y = 50;
    }
    public integer x { get; set; }
    public integer y { get; set; }
}

2) Setter methods

 

You can determine if a component is already initialized, and skip the logic if we're already initialized. This is most useful for component parameters.

 

Example:

 

<apex:component controller="compCont">
    <apex:attribute name="info" description="some data" type="String" assignTo="{!data}"/>
    ...
</apex:component>
public with sharing class compConv {
    boolean hasInit;
    public compConv() { hasInit = false; }
    public void setData(String data) {
        if(hasInit) return;
        // Do one time init here
    }
    // Required to satisfy getter/setter, but we don't care.
    public string getData() { return null; }
}