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
MarrisMarris 

Need help on refreshing a page in force.com sites

Hi

 

     I created a force.com site page and gave authentication to customer portal users to access the page. The force.com site page have callout on pageload as callout1 and callout2 on a button click.

 

Callout1 - I show some list from external system with a button deactivate

 

Callout2 - When the user clicks deactivate then that row is eliminated from the list in the external system

 

Now I refreshes the page when callout2 is over but the salesforce took the page from Cache because the deactivated column is showing on Callout1 list.When I press F5 it shows the correct result by eliminating the column.

 

Eg) List shows Item1 then deactivate button,item2 then deactivate button

 

When I click deactivate button on item2, it deactivated and eliminated.

 

On refreshing a Page by pagereference Still shows item2 on List but by Pressing F5 it shows correctly by elimination

 

Need help on this

 

Thanks

Marris

AdrianCCAdrianCC

Hi,

 

So, if I'm gettin this correctly you have 2 actions: 1 taht list some records, and 2nd that removes records from that list. On the rerender of the page after action2 the list still has the initial value.

 

Solution is simple: in your controller action2 method, at the end of it, after the remove part reinstantiate the record list to refresh its value. Probably a call to action1 is what you need...

 

Thanks,

Adrian

 

MarrisMarris

Hi AdrianCC

 

       Thanks for your help but it is not working

 

       I made a call of first callout at the end of action method as you have mentioned but still it shows the eliminated value in the list. But after a page refresh I call the callout1 means it shows the list excatly by eliminating the values.

 

Thanks

Marris

AdrianCCAdrianCC

You need to debug it to see exactly where the problem is, controller or page.

For the controller, put System.debug(recordList) at the end of both methods to see how if the value is refreshed corectly.

Also in the VF page try adding a rerender attribute to your commandbutton, and rerender only the part that shows the list. 

 

A quick fix would be to change the return type of the action2 to PageReference and return the same page at the end of the method. This would simulate the user clicking F5 on the page...

 

Can you post the vf page and actions 1 & 2 code here?

 

Thanks,

Adrian

MarrisMarris

Hi AdrianCC

 

Here is my page

 

 <apex:outputPanel id="FList">

 <div style="margin-left:10px;margin-bottom:20px;width:630px;height:165px;overflow:auto;float:left">

   <apex:dataTable id="solution" value="{!FeatureList}" var="FL" headerClass="fixedheader" rowClasses="normalRow,alternateRow" width="100%">

   <apex:column headerValue="Feature Name" width="40%" style="height:30px;padding-left:0px">
   <apex:outputText value="{!FL.feature}" />
   </apex:column>
                            
   <apex:column headerValue="Status" width="40%" style="height:30px;padding-left:0px">
   <apex:commandLink value="{!FL.Active}" style="font-weight:normal;color:#1566C2;" action="{!ActivateFeature}" onclick="load();">
   <apex:param name="FeatureId" value="{!FL.featurecode}" assignTo="{!rem}" />
   <apex:param name="Featureactive" value="{!FL.isActivated}" assignTo="{!rem1}" />
   </apex:commandLink>
   </apex:column>

     </apex:dataTable>
       </div> 
         </apex:outputPanel>

 

Apex class:

 

Callout2 on a button click

 

 public pagereference activateFeature(){
        String FActive;
        String featurcode = ApexPages.currentPage().getParameters().get('FeatureId');
        system.debug('New Feature code :'+featurcode);
        String featuractive = ApexPages.currentPage().getParameters().get('FeatureActive');
        system.debug('New Feature active :'+featuractive);
        if(featuractive == 'True'){
            FActive = 'D';
        }else{
            FActive = 'A';
        }
        //Made a callout here and get the response in String response


        System.debug('The Response is:'+response);
         if(response != null && response.trim() != ''){
        
        Map<String, String> outputDetails = abc.parseDetails( response );
        System.debug('Response detail is:'+outputDetails);
        System.debug('Response code:'+outputDetails.get( 'ResponseCode' ));
        System.debug('Result is:'+outputDetails.get( 'Result' ));
        System.debug('Response Msg:'+outputDetails.get( 'ResponseMessage' ));
        //System.debug();
        try{
        if(outputDetails.get( 'Result' ) == 'SUCCESS'){
            String Responsecode = outputDetails.get( 'ResponseCode' );
            String Responsemsg = outputDetails.get( 'ResponseMessage' );
             ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Info,'Plan Feature Changed Successfully'));
             
        }else{
            String Errorcode = outputDetails.get( 'ErrorCode' );
            String Errormsg = outputDetails.get( 'ErrorMessage' );
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Info,'Plan Feature not Updated.Please Try again later'));
            return null;
        }
        }catch(Exception e){
            System.debug('Exception:'+e);
        }
       }
       featureList.clear();
       planfeature();    //Callout1

       System.debug('Callout1 List:'+FeatureList); // It shows only a old list which is not updated with elimination
       pagereference page = new pagereference('/apex/mypage');
       return page;       
    }

 

Callout1:

 

Made a callout named "planfeature()" and return a list of plan features, Callout1 is called in class constructor

 

Thanks

marris

AdrianCCAdrianCC

What are you using for the callouts, HttpRequest class?

Are they running synchronously or asynchronously(are you using @future adnotation)? What's the timeout?

 

Adrian

SFFSFF

You may want to add cache="false" as an attribute on the <apex:page> tag - at least that helps me when I had a similar problem with a Sites page recently. Sites seems to assume that you are doing a public-facing website and that, for performance reasons, you will want to cache as much as possible.

 

Hope this helps,

MarrisMarris

Hi Adriancc

 

             I am using Http callout synchronously and i didnt mention any time out for it

 

 

Thanks

Marris

MarrisMarris

Hi SFF

 

         I added the cache as false in page but still faces the same error.

 

 

Thanks

Marris

AdrianCCAdrianCC

This is wierd... I was thinking your callout was asynchronously and that was the problem, but since it's not then it should wait for the operation to finish and then rerender the page...

 

What does that 

onclick="load();"

javascript do? does it have anything to do with the list? or other callouts?

 

As for the refresh problem at hand. You could try manually removing the element from the list when response == SUCCESS without doing the whole retrieve through callout1. 

 

LE: typo

 

Thanks,

Adrian