2

I have two objects - Project and Resource . Project is a lookup field on Resource. So in Project there is a related list called Resources.

Now in Resource , I have created a list button "Add project Resource" which calls a VF page(having custom controller). There is a commandbutton on the VF page like this

<apex:commandButton value="Save" action="{!save}"/>

and in controller

public PageReference save()
{

 //....do some calculation
 //...insert a new resource....
   return new Pagereference('/'+project.id);
}

So basically it creates a new resource and navigates back to its parent project . Problem this when I am Switching to lightning experience , it does navigate to the project record but its resource related list is not updated. I need to refresh the project record manually and then it shows the newly added resource in the resource related list.

Is there some cache problem ?

I have tried using sforce.one.navigateToSObject("{!project.id}") when its lightning but same problem occurs.

Please help.

2

Indeed, just redirecting to the record will not fire a refresh event. However, sforce.one.back takes a "refresh" parameter, so if you only need to go back to the record you were on (a "nav back") you can just use sforce.one.back(true).

There's an [example of this as a VF component][https://github.com/SalesforceFoundation/Cumulus/blob/dev/src/components/UTIL_NavigateBack.component] in the NPSP:

<apex:component >
    <apex:attribute name="recordId"
        description="The recordId to navigate to."
        type="Id"
        required="true"
        />
    <apex:attribute name="redirect"
        description="Prevent redirect unless set to true."
        type="Boolean"
        default="false"
        />

    <script type="text/javascript">
        var redirect = {!redirect};
        if (redirect) {
            if ((typeof sforce != 'undefined') && sforce && (!!sforce.one)) {
                // Manage navigation in Lightning Experience & Salesforce1
                    sforce.one.back(true);
            }
            else {
                var recordId = '{!recordId}';
                // Manage navigation in Salesforce Classic
                window.parent.location.href = '/' + recordId;
            }
        }
    </script>

</apex:component>
| improve this answer | |
  • Strangely still it fails sometimes....problem is its very unpredictable.....Usually its failing for the first time (when it navigates back and lands on the detail tab of the record , when I click on related list tab the resource related list is being shown as empty although we have added a resource) . Any other solution @ChristianCarter ?? – Anindya Halder Dec 6 '16 at 15:17
  • Lightning maintains the cache for resource map layout and set it's respective refresh time. Every time we redirect from custom page to detail page, UI not reflecting it's updated value. sforce.one.back(true) is also not working in MS Edge because given method work on state and MS edge saving every stages in session. How can we forcefully refresh view in lightning? – dgk Mar 1 '17 at 13:18
  • Using sforce.one.back(true) hasn't worked for me at all and the page is not being refreshed. – John_Henry Jun 21 '17 at 17:20
1

Can you try out using <apex:commandLink> instead of <apex:commandButton> and perform navigation from javascript.

<apex:commandLink value="Save" action="{!save}" oncomplete="return handleRedirect()"
                   target="_top" 
                   styleClass="btn" 
                   style="text-decoration:none;padding:4px;">
<script>
    function handleRedirect() {
            if((typeof sforce != 'undefined') && sforce && (!!sforce.one))
            {
               sforce.one.navigateToSObject(recordId,view);
            } else {
                window.location.href = '<your url>';
            }

    }
</script>
| 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.