6

I have a problem that I think is related to caching. I have an object with record types that has two page layouts with different buttons. I have different page layouts assigned to those record types. I then have a Visualforce page that is accessed from the record page to make some edits and then on save of that page, sends the user back to the record page. (I realize I could use a Lightning Component to make this nicer, but we are in the transition from Classic to Lightning, so I need it to work in both places.) As part of the edit, the record type gets changed, but when the user is returned back to the record, the record type isn't changed. I have to refresh several times to first get the record type to display the correct one and then a few more times to get the buttons to display the correct buttons.

Steps to recreate:

  1. Create a custom object with 2 record types.
  2. Create 2 URL buttons that point to something like https://salesforce.stackexchange.com. Label them button 1 and button 2.
  3. Create 2 page layouts. Add one of the buttons to each in the Lightning and Mobile actions section.
  4. Assign page layouts to the record types.
  5. Create a VF page that allows the user to edit the record type. (Code below)

  6. Create a button to change the record type and add it to each page layout.

Now that you have it all setup, click the button for your visualforce page, change the record type, and Save. Note that the record page doesn't reflect the changes. Refresh, you might see a case where the RT shows changed, but the buttons aren't. Keep refreshing and see the buttons finally change. I can't recreate this behavior if I change the RT directly on the page.

Page code:

 <apex:page standardController="Lightning_Demo__c" title="Interstitial Page" lightningStylesheets="true">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:inputField value="{!Lightning_Demo__c.RecordTypeId}" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!Save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Here's what it should look like after changing from RT 2 to RT 1:

RT and Buttons Correct

But I get a page like this where the buttons are for the previous record type, but the details shows the correct record type:

enter image description here

  • I think you need to force:refreshView, which is complicated because you're in Visualforce, but this Q&A might help you. – sfdcfox May 15 '18 at 0:29
  • My VF page isn't embedded on the record page, though. I'm navigating from one page to another. – Daniel Hoechst May 15 '18 at 14:46
0

I finally found out that this is a known issue: https://success.salesforce.com/issues_view?id=a1p3A0000001C8QQAU.

The recommended solution is to refactor the component to use Lightning Data Service (force:recordData). Lightning Data Service provides a performance increase and eliminates out-of-sync issues. If you can’t refactor your component to use Lightning Data Service, you can also use force:refreshView to request a page refresh.

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.