[SalesForce] How to save and close the visualforce page in Chrome

I´ve tested this on Google Chrome and Microsoft Edge. On Chrome, it rarely saves. On Edge, it always saves.

I´ve disabled all plugins, cleared cookies, allowed popups, etc., for Chrome, but none of this has solved the problem.

I think the issue is that the page is closed before it can be saved. When I remove this:

onclick="window.top.close()"

…the page always saves in Chrome too.

Is there a way to save and close the page without having this issue?

Here´s the vf page (the idea is that you click on a button, the vf page appears as a full-screen popup, you type the Campaign Name, Save, the popup closes, and a new Campaign Member is hopefully created, and visible in the related list after the Contact page is refreshed):

<apex:page standardController="CampaignMember">
<apex:form >
<apex:outputPanel id="CmPage">
<apex:pageMessages />
<apex:messages />
<apex:pageBlock mode="edit">
<apex:pageBlockSection columns="1">
<apex:inputfield value="{!campaignmember.campaignid}" label="Campaign Name" id="cmName"/>
<apex:inputfield value="{!campaignmember.Contactid}" label="Contact" id="CampaignMemberContactId" />
<script>
        document.getElementById('{!$Component.CampaignMemberContactId}' + '_lkid').value = '{!$CurrentPage.parameters.ContactId}';
        document.getElementById('{!$Component.CampaignMemberContactId}' + '_lkold').value = '{!$CurrentPage.parameters.ContactName}';
        document.getElementById('{!$Component.CampaignMemberContactId}' + '_mod').value = 1;
        document.getElementById('{!$Component.CampaignMemberContactId}').value = '{!$CurrentPage.parameters.ContactName}';
    </script>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!quicksave}" onclick="window.top.close()"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel> 
</apex:form>
</apex:page>

Best Answer

Please try the following way:

<apex:actionFunction name="quickSaveJavascript" action="{!quicksave}" oncomplete="window.top.close();"/>
<apex:commandButton value="Save" onclick="quickSaveJavascript();"/>

=====================

If the above doesn't work, another option is to use Visualforce Remoting, but for that you need custom controller

In javascript, call Visualforce Remoting

CustomController.save(
   records,
   function () {
       window.top.close();
   }
)

If my answer works for you, please mark it as accepted.

Related Topic