-1

How to create a refresh button on my visualforce page

public PageReference save(){
        try{
            upsert orgInfo;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Created successfully'));
        }
        catch(System.DMLException e){
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,''));
            return null;
        }
        orgInfo = null;
        ScheduledOrgInfoFetch.ScheduledOrgInfoFetch();
        return null;        
    }

Updated :
Org Information Client ID:

Client Secret:

Username:

Password:


Sandbox?


enter code here
  • Can you add little bit more information about your use case so that members can give you proper direction. And what you have tried so far? – Santanu Boral Aug 31 '18 at 7:22
  • I have added my comment on how to refresh the form after save, please check your earlier Question. – Saroj Bera Aug 31 '18 at 7:26
  • the code in on the above – jan Aug 31 '18 at 7:33
0

If you want to get the refreshed view after an update, You can achieve it as follows:-

if you are trying to get refreshed view in classic mode:-

       public PageReference save(){
            try{
                 upsert orgInfo;
                 if(UserInfo.getUiThemeDisplayed()=='Theme3' ){
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Created successfully'));
                 PageReference pr = new PageReference('/' +orgInfo.id);
                 pr.setRedirect(true);
                 return pr;  
                }else{
                return null;
            } 
            catch(System.DMLException e){
                  ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,''));
                return null;
            }
        }

This should give you a refreshed view in Classic mode. Many a time pagereference does not give you a refreshed view in Lightning, hence just I keep pagereference limited to classic view.

For Lightning what you all need is:-

In your visualforce page, you need to include below code:-

<script>
    function  refresh(){
    sforce.one.back(true);
        }
</script>

And render your save button for Lightning separately. the first button will render in classic i.e theme 3 and the second one will render in Lightning i.e theme 4d.

<apex:commandbutton value="Save" action="{!saveRecord}" rendered="{!$User.UITheme == 'Theme3'}"/>
    <apex:commandbutton value="Save" action="{!saveRecord}" oncomplete="return refresh();" rendered="{!$User.UITheme == 'Theme4d'}"/>
  • it's not working.. the data are still there. further explanation please – jan Aug 31 '18 at 8:06
  • Can you once change the method name and try?? Or try to post your vf page required snippet too. – sanket kumar Aug 31 '18 at 8:11
  • i follow the codes that you give but there's an error. the error was "The Apex job named "Client Info" is already scheduled for execution." – jan Aug 31 '18 at 8:34
  • I.e because in finally block, you are calling the schedulable class to schedule a job. Once it is scheduled already, maybe that's why it is giving you an error. Is it necessary to call a schedulable class and schedule a job every time a record gets updated? Can you tell me more about your functionality? – sanket kumar Aug 31 '18 at 8:41
  • yeah, your right are we going to catch that error? – jan Aug 31 '18 at 8:51
0

You can use render attribute of action for particular element where your upsert property is reffered it will automatically update new changes on UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.