0

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

Your Answer

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

Browse other questions tagged or ask your own question.