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
Jerun JoseJerun Jose 

Updating page with status of a long transaction

Hi,

 

I am working on a visualforce page which is used to integrate SFDC data with an external system.

The integration process involves multiple callouts (about 5) which can take up a lot of time. Is it possible to update the visualforce page to display the status of the transaction?

 

Say if the method which is called from the page is

public someReturn someMethod(){
	method1();
	// say status is s1
	method2();
	// say status is s2
	method3();
	// say status is s3
	method4();
	// say status is s4
	method5();
	// say status is s5
}

 How can we display the status of the method 'someMethod' to update the page with the statuses s1, s2 ..

 

Any suggestions are welcome.

 

Thanks,

 

Jerun Jose

Eugene PozniakEugene Pozniak

I never used this tag but think it can be helpful for you. 

 

See documentation.

 

I think it can be possible to do something like this:

Page:

<apex:page controller="yourController">
    <apex:form>
        <apex:outputText value="Status: {!status}" id="status" />
        <apex:actionPoller action="{!refreshStatus}" rerender="status" interval="15" />
		. . . 
    </apex:form>
</apex:page>

 Controller:

public class yourController {
    public String status { get; set; }
	
    public yourController() {
	status = 'Not started';
    }
			
    public PageReference refreshStatus() {
        return NULL;
    }
			
    public someReturn someMethod(){
		method1();
		status = 'The first method, completed its work';
		method2();
		status = 'The second method, completed its work';
		. . . 
	}
}

 

 

Jerun JoseJerun Jose

Hi,

 

I tried your approach and it isnt working. I did a bit of experimentation myself and think I have a basic problem here.

 

My VF page code is :

 

<apex:page standardController="Opportunity" extensions="someController">
	<apex:form>
		<apex:actionPoller action="{!bigMethod}" interval="500" enabled="{!!started}" status="SyncStatus" />
		<apex:actionStatus id="SyncStatus" startText="Loading ... " stopText="Sync Complete"/>
		<br/>
		<apex:actionPoller interval="5" status="refStatus" rerender="counter" action="{!refreshStatus}"/>
		<apex:actionStatus id="refStatus" startText="Loading count ... " stopText="Call Complete"/>
		<apex:outputText value="count = {!count} for {!NOW()}" id="counter"/>
	</apex:form>
    <apex:pageMessages ></apex:pageMessages>
</apex:page>

 A simplified apex code behind this is

 

public class someController {

	public boolean started{get;set;}
	public Integer count{get;set;}

    public PageReference refreshStatus() {
		system.debug('@@@@@@@@@ count = '+count);
        return NULL;
    }

	public someController(ApexPages.StandardController controller){
		started = false;
		count = 0;
    }

	public PageReference bigMethod(){
		started = true;
		PageReference pf = null;
		m1();
		count++;
        m2();
		count++;
        m3();
		count++;

		pf = new PageReference('somewhere');
		return pf;
	}
}

 

The actionPoller for refreshStatus is running and updates the current time properly using the NOW() function, but it is not able to fetch the latest value for count.

Even the debugs for the poller show the count value of initial 0.

After a while though, the "bigMethod" completes and returns the pageReference, but all the while the count in the debug and the outputText stay 0.

 

Can anyone explain why ??

 

Thanks,

 

Jerun Jose