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
Cloud EliteCloud Elite 

visualforce button is not working need alternative

is there any other alternative for the following code to work ? i need lightening component instead. 
 
<apex:page standardController="Lead" tabStyle="Lead" sidebar="false" lightningStylesheets="true" docType="HTML-5.0" >

    <script src="/soap/ajax/43.0/connection.js" type="text/javascript"/>
    
    <script>
        function ReloadPage(){
            setTimeout(function(){ window.top.location='/{!Lead.Id}'; }, 100);
        }
    </script>
 
 <apex:form >
    <apex:inlineEditSupport showOnEdit="SaveButton" /> 
    <apex:slds />
    <div class="slds-scope">
    <center>
        <apex:commandButton value="Save" action="{!Save}" onclick="ReloadPage()" style="display: none;" id="SaveButton" />
    </center>
    
    <table class="slds-table slds-table_bordered slds-table_cell-buffer"> 
    
        <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_col-bordered"> 
    
        <thead>
            <tr class="slds-text-title_caps slds-text-heading--label">
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Class">Class</div>  
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Scheduled">Scheduled</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Claimed">Claimed</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Allowed">Allowed</div>       
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="CUD">CUD</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Status">Status</div>       
                </th>     
            </tr>
        </thead>
        <tbody>
            <tr>
                <td scope="row" >
                    Secured
                </td>
                <td>
                    {!Lead.Secured_CUD__c}
                </td>
                <td>
                    {!Lead.Secured_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Unsecured 
                </td>
                <td>
                    {!Lead.UnSecured_CUD__c}
                </td>
                <td>
                    {!Lead.Unsecured_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Priority 
                </td>
                <td>
                    {!Lead.Priority_CUD__c}
                </td>
                <td>
                    {!Lead.Priority_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Admin 
                </td>
                <td>
                    {!Lead.Admin_CUD__c}
                </td>
                <td>
                    {!Lead.Admin_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Admin503B 
                </d>
                <td>
                    {!Lead.Admin503B_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Totals  
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Scheduled__c}"/>
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Claimed-__c}"/>
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Allowed__c}"/>
                </td>
                <td>
                    
                </td>
                <td>
                    
                </td>
            </tr>
        </tbody> 
    </table>
    </table>
    </div>
  </apex:form>
</apex:page>

 
Best Answer chosen by Cloud Elite
Alain CabonAlain Cabon
Hi,

The javascript button doesn't work in Ligthning.
<script>
        function ReloadPage(){
            setTimeout(function(){ window.top.location='/{!Lead.Id}'; }, 100);
        }
</script>

You can rewrite completely your VFP in Lex (Lightning Experience) but that is not necessary and that is quite complicated for a result not different for the end user (SLDS is already used here).

You just need an extension (apex class): LeadCtrl
 
public class LeadCtrl {
    public Lead lead {get;set;}
    public LeadCtrl(ApexPages.StandardController stdController) {
           lead = (Lead)stdController.getRecord();
    }
    public PageReference save() {
       if (lead.id != null) {
              update lead;
            return new PageReference('/' + lead.Id);
       }
       return null;
    }
}

<apex:page standardController="Lead" extensions="LeadCtrl" tabStyle="Lead" sidebar="false"
 
<apex:page standardController="Lead" extensions="LeadCtrl" tabStyle="Lead" sidebar="false" lightningStylesheets="true" docType="HTML-5.0" >
 <apex:form >
    <apex:inlineEditSupport showOnEdit="SaveButton" /> 
    <apex:slds />
    <div class="slds-scope">
    <center>
        <apex:commandButton value="Save" action="{!Save}"  id="SaveButton" />
    </center>   
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">    
        <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_col-bordered">     
        <thead>
            <tr class="slds-text-title_caps slds-text-heading--label">
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Class">Class</div>  
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td scope="row" >
                    Nummber of employees
                </td>
                <td>
                  <apex:outputField value="{!Lead.NumberOfEmployees}" />
                </td>          
            </tr>
        </tbody> 
    </table>
    </table>
    </div>
  </apex:form>
</apex:page>

All Answers

Alain CabonAlain Cabon
Hi,

The javascript button doesn't work in Ligthning.
<script>
        function ReloadPage(){
            setTimeout(function(){ window.top.location='/{!Lead.Id}'; }, 100);
        }
</script>

You can rewrite completely your VFP in Lex (Lightning Experience) but that is not necessary and that is quite complicated for a result not different for the end user (SLDS is already used here).

You just need an extension (apex class): LeadCtrl
 
public class LeadCtrl {
    public Lead lead {get;set;}
    public LeadCtrl(ApexPages.StandardController stdController) {
           lead = (Lead)stdController.getRecord();
    }
    public PageReference save() {
       if (lead.id != null) {
              update lead;
            return new PageReference('/' + lead.Id);
       }
       return null;
    }
}

<apex:page standardController="Lead" extensions="LeadCtrl" tabStyle="Lead" sidebar="false"
 
<apex:page standardController="Lead" extensions="LeadCtrl" tabStyle="Lead" sidebar="false" lightningStylesheets="true" docType="HTML-5.0" >
 <apex:form >
    <apex:inlineEditSupport showOnEdit="SaveButton" /> 
    <apex:slds />
    <div class="slds-scope">
    <center>
        <apex:commandButton value="Save" action="{!Save}"  id="SaveButton" />
    </center>   
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">    
        <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_col-bordered">     
        <thead>
            <tr class="slds-text-title_caps slds-text-heading--label">
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Class">Class</div>  
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td scope="row" >
                    Nummber of employees
                </td>
                <td>
                  <apex:outputField value="{!Lead.NumberOfEmployees}" />
                </td>          
            </tr>
        </tbody> 
    </table>
    </table>
    </div>
  </apex:form>
</apex:page>
This was selected as the best answer
Cloud EliteCloud Elite
@alain , can you please share test class for that class please ?
Alain CabonAlain Cabon
Hi,
 
@isTest
public class LeadCtrlTest {   
    static testMethod void MyTest()
    {        
        Lead myLead = new Lead(Company = 'Test Lead', LastName = 'Lead Last Name', Status = 'Open', NumberOfEmployees = 0);
        Apexpages.StandardController sc1 = new Apexpages.StandardController(myLead);
        LeadCtrl ext1 = new  LeadCtrl(sc1);
        // id doesn't exist - return null
        PageReference actualpage = ext1.save();
        system.assertEquals(null, actualpage);
        insert myLead;
        // id created (insert done)
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myLead);
        LeadCtrl ext = new  LeadCtrl(sc);
        ext.lead.NumberOfEmployees = 100;
        // id exists now
        PageReference actualpage2 = ext.save(); 
        Lead updatedLead = [select  Id,NumberOfEmployees from Lead where id = :myLead.Id ];
        
        integer expected_number = updatedLead.NumberOfEmployees;
        integer actual_number =  ext.lead.NumberOfEmployees;
        system.assertEquals(expected_number, actual_number);
       
        system.assertEquals('/' + updatedLead.Id, actualpage2.getUrl());
    }
}

It is more to give some examples of standard tests for an extension than the minimal sufficient test for the 100%.
Cloud EliteCloud Elite
i applied this fix to prod but it does not seem to fix the issue. the edit button is not working. i really appreciate the help so far but i really don't know whats the issue with that page. i submitted a ticket to salesforce. i will let you know. 
Cloud EliteCloud Elite
would you please share with me sample code for lightening component and conroler ? i think i need to do this since the page didn't work
Alain CabonAlain Cabon
The code I posted works.It is a real test on a developer console but you have not posted your complete final code here.

The better thing to do now is to open a new question because no one will comment an old question excepted me and you will be more successful with a new fresh question.

Samples for Lightning Component and Controller: the trailhead projects are full of complete samples
Becoming a developer for Ligtnning component, complete trail:  https://trailhead.salesforce.com/en/trails/lex_dev
https://developer.salesforce.com/forums/?id=9060G0000005mpwQAA
https://developer.salesforce.com/forums/?id=9060G0000005m4vQAA 
Cloud EliteCloud Elite
here is the complete code for the VF 

<apex:page standardController="Lead" extensions="LeadCtrl" tabStyle="Lead" sidebar="false" lightningStylesheets="true" docType="HTML-5.0" >
 
    <apex:form >
    <apex:inlineEditSupport showOnEdit="SaveButton" /> 
    <apex:slds />
    <div class="slds-scope">
    <center>
        <apex:commandButton value="Save" action="{!Save}" onclick="ReloadPage()" style="display: none;" id="SaveButton" />
    </center>
    
    <table class="slds-table slds-table_bordered slds-table_cell-buffer"> 
    
        <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_col-bordered"> 
    
        <thead>
            <tr class="slds-text-title_caps slds-text-heading--label">
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Class">Class</div>  
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="Scheduled">Scheduled</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Claimed">Claimed</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Allowed">Allowed</div>       
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                  <div class="slds-truncate" title="CUD">CUD</div>      
                </th>
                <th scope="col" class="slds-cell-buffer_left">
                 <div class="slds-truncate" title="Status">Status</div>       
                </th>     
            </tr>
        </thead>
        <tbody>
            <tr>
                <td scope="row" >
                    Secured
                </td>
                <td>
                 <apex:outputfield value="{!Lead.Secured_Scheduled_Amount__c}"/>
                </td>
                <td> 
                  <apex:outputfield value="{!Lead.Secured_Claimed_Amount__c}"/>  
                </td>
                <td>
                  <apex:outputfield value="{!Lead.Secured_Allowed_Amount__c}"/>  
                </td>
                <td>
                    {!Lead.Secured_CUD__c}
                </td>
                <td>
                    {!Lead.Secured_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Unsecured 
                </td>
                <td>
                  <apex:outputfield value="{!Lead.Unsecured_Scheduled_Amount__c}"/>  
                </td>
                <td> 
                   <apex:outputfield value="{!Lead.Unsecured_Claimed_Amount__c}"/>
                </td>
                <td>
                  <apex:outputfield value="{!Lead.Unsecured_Allowed_Amount__c}"/>
                </td>
                <td>
                    {!Lead.UnSecured_CUD__c}
                </td>
                <td>
                    {!Lead.Unsecured_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Priority 
                </td>
                <td>
                  <apex:outputfield value="{!Lead.Priority_Scheduled_Amount__c}"/>  
                </td>
                <td> 
                  <apex:outputfield value="{!Lead.Priority_Claimed_Amount__c}"/>  
                </td>
                <td>
                   <apex:outputfield value="{!Lead.Priority_Allowed_Amount__c}"/> 
                </td>
                <td>
                    {!Lead.Priority_CUD__c}
                </td>
                <td>
                    {!Lead.Priority_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Admin 
                </td>
                <td>
                 <apex:outputfield value="{!Lead.Admin_Scheduled_Amount__c}"/>   
                </td>
                <td> 
                 <apex:outputfield value="{!Lead.Admin_Claimed_Amount__c}"/>   
                </td>
                <td>
                 <apex:outputfield value="{!Lead.Admin_Allowed_Amount__c}"/>   
                </td>
                <td>
                    {!Lead.Admin_CUD__c}
                </td>
                <td>
                    {!Lead.Admin_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Admin503B 
                </td>
                <td>
                 <apex:outputfield value="{!Lead.Admin503B_Scheduled_Amount__c}"/>   
                </td>
                <td> 
                 <apex:outputfield value="{!Lead.Admin503B_Claimed_Amount__c}"/>   
                </td>
                <td>
                 <apex:outputfield value="{!Lead.Admin503B_Allowed_Amount__c}"/>  
                </td>
                <td>
                    {!Lead.Admin503B_CUD__c}
                </td>
                <td>
                    {!Lead.Admin503B_Claim_Status__c}
                </td>
            </tr>
            <tr>
                <td scope="row" >
                    Totals  
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Scheduled_Total__c}"/>
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Claimed_Total__c}"/>
                </td>
                <td>
                    <apex:outputfield value="{!Lead.Allowed_Total__c}"/>
                </td>
                <td>
                    
                </td>
                <td>
                    
                </td>
            </tr>
        </tbody> 
    </table>
    </table>
    </div>
  </apex:form>
</apex:page>

class: 
same as the one your provided. 

this does not work in production