2

I am attempting to emulate a Confirm process that was once handled well by a Javascript button. The idea is to ask for a Confirmation when attempting to deactivate a record.

To do this, I am creating a simple VF page using an controller extension. The PageMessages receive an INFO level confirmation message, and the button will call a method to deactivate and save the record, then redirect back to it:

From the record detail in Lightning Experience, I have a quick action button that references a VF page.

Ultimately the process is working, but when the page redirects back to the original record, the Active switch is still appears as checked, even though one or two hard refreshes show that its actually deactivated in the database. Here is the code

<apex:page standardController="Activity__c" extensions="Deactivate">
<apex:pageMessages />
<apex:form >
    <apex:pageBlock>
        <apex:pageBlockButtons location="top">
            <apex:commandButton action="{!DeActivate}" value="DeActivate Activity" rendered="{!Active = true}"/>
            <apex:commandButton action="{!Cancel}" value="Cancel" />
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>

public with sharing class DeactivateController{
Public Activity__c pActivity {get; set;}
Public Boolean Active {get; set;}

public Deactivate(ApexPages.StandardController ctr){
    this.pActivity = (Activity__c) ctr.getRecord();
    this.pActivity = [Select id, Active__c from Activity__c Where Id = :this.pActivity.Id];
    Active = this.pActivity.Active__c;
    confirm();
}

private void confirm(){
    if (Active){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Confirm Deactivate?'));
    }
}

public pageReference DeActivate(){
    pActivity.Active__c = False;
    update pActivity;
    PageReference pageRef = new PageReference('/'+pActivity.Id);

    pageRef.setRedirect(true);
    return pageRef;

}
}

I've also tried new PageReference('/one/one.app#/sObject/'+pActivityId+'/view'); as well as the full URL with https In all cases, the Record page returns, but Active still appears checked, even though it isn't in the database. If I refresh the page a couple of times, it finally comes up correct.

  • I actually have to refresh the page one or two times after the operation to show the correct value. I don't understand that at all. – VeMan Aug 10 '17 at 18:00
  • This page will not compile nor will the class due to name mismatches – Eric Aug 22 '17 at 4:40
  • Did you ever find a solution to this? – Marc M. Nov 6 '17 at 14:17
  • I don't think we did. Ultimately we chose to accept that the deactivation was taking place and redirected the user to another page. – VeMan Nov 6 '17 at 18:21
  • Just in case you never figured this out, you may want to have a look at my solution. – Mr. B Dec 10 '19 at 20:22
1

I finally figured this out. This is actually a known issue between VF and background Apex changes (thanks Salesforce), along with navigation back to a Standard Page via PageReference:

https://success.salesforce.com/issues_view?id=a1p3A0000001C8QQAU&title=data-not-updated-in-ui-after-an-apex-update-in-lightning-experience

I found this Post that explained how to use remoting to force the refresh (in Lightning):

https://www.sales4k.com/sfdc/salesforce-lightning-refresh/

Unfortunately, that also did NOT (or no longer does) work either. It did however lead me to Googling caching issues with sforce.one.navigateToSObject in Lightning, where I found a Post that said sforce.one.back(true) does work in Lighting. Finally, I got it to work, using this approach. The following example illustrates my final solution:

Visual Force .page file:

<apex:page controller="YOUR_CONTROLLER" action="{!Launch}" cache="false" 
 lightningstylesheets="true">

   <script src="/soap/ajax/38.0/connection.js" type="text/javascript"></script>
   <script src="/soap/ajax/38.0/apex.js" type="text/javascript"></script>
   <script type="text/javascript">

      // Back NAV.Refreshed
      sforce.one.back(true); // While sforce.one.navigateToSObject(YOUR_ID) did NOT 
                             // refresh, sforce.one.back(true) did refresh

    </script>
</apex:page>

Apex Controller

global class YOUR_CONTROLLER  
{   
   public void Launch()
   {
      // Your update logic goes here (will properly refresh on backward navigation)
      ...
   }
}
| improve this answer | |
0

Here is an easy solution to this problem. reload the page using apex:commandLink with target ="_top" OR target="_parent".

At visualforce page have this

<apex:page controller="xyz" lightningstylesheet="true">
<!--
Your any page side tag
-->
<apex:commandLink action="{!redirectWithRefreshValue}" target="_top" >Click to go back to Lightning Detail record Page</apex:commandLink>

</apex:page>

//Apex Controller Code method
public PageReference redirectWithRefreshValue(){
 return new PageReference('/'+recordId);
}
| improve this answer | |

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.