function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fabio PalladinoFabio Palladino 

Custom Action with not rendered VF page

Hi All,
I need to create a custom action for LEX environment placed in a detail page of custom Object.
This action must execute a JS remote invocation to an apex class that update one field on record in context.
After this the record must be refreshed and new value of custom field displayed.
I have created:
  • An Apex controller extension for custom Object that performs field update on the record visualized (@remote method) 
  • A VF page that embed JS remote invocation to Apex method
  • A custom Action of type "Custom Visualforce"
I added the action on Object Page Layout and It works but when I click on the button I visualize, for a few seconds, a blank popup page like this:
Blank VF page

I don't need to visualize any Grafical VF page I only need to perform JS invocation.
This is VF page:
<apex:page standardController="Quote__c" extensions="Test4SyncController" docType="html-5.0" standardStylesheets="false" showheader="false" sidebar="false">

<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>
<script>
    
    UpdateAccount();


function UpdateAccount(){
    aId = '<apex:outputText value="{!Quote__c.Id}"/>';
    
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Test4SyncController.updateAccount}', aId,
                                              function(result, event){;
                                                                      if(event.status){
                                                                          // Success - close the publisher and refresh the feed.
                                                                          Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});  
                                                                      } else if (event.type === 'exception'){
                                                                          console.log(result);
                                                                      } else {
                                                                          
                                                                      }
                                                                     });
}

</script>       


</apex:page>

You know any way to perform this requirement ?

Thanks in advance for your reply
jprichterjprichter
Since you're using LEX, you might want to consider using a Lightning Component that makes a callout to an @AuraEnabled Apex method. This Component would be held in a Visualforce page using Lightning Out. There's a blog about how to do this here. (http://www.crmscience.com/single-post/2016/08/11/Buttons-and-Actions-in-the-Salesforce-Lightning-Experience)