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
KPJSKPJS 

Need to create a Lightning Button that does nothing

Hello - we have a LOT of buttons for the same purpose: a series of contracts buttons, on the Account object. My manager didn't want them all running across the page so I have them all in the drop down menu. He then asked me to create a fake button that pointed users to the menu, it reads Contracts >, best I could do, but people are clicking on it, which just creates an error. 

So, does anyone know how to create a button that either does nothing without erroring, or just keeps them on the existing Account? I tried using {!Account.Id} or Account.Link, but it just appends the existing URL with this link. I do have it set to Display in existing window without sidebar. 

Anyway, any ideas would be welcome. Thanks!
Best Answer chosen by KPJS
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

You can create the lightning component to refresh the page on button click using force:refreshView which just refresh the page without making any changes.

Reference the sample code for the same in the below blog:

https://www.forcetalks.com/salesforce-topic/how-to-refresh-component-after-button-click-for-viewing-updated-values-after-refreshing-page-in-salesforce-lightning/

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

You can create the lightning component to refresh the page on button click using force:refreshView which just refresh the page without making any changes.

Reference the sample code for the same in the below blog:

https://www.forcetalks.com/salesforce-topic/how-to-refresh-component-after-button-click-for-viewing-updated-values-after-refreshing-page-in-salesforce-lightning/

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
This was selected as the best answer
KPJSKPJS
Hi Shirisha: Thank you! This looks really interesting and not just for this purpose! Forgive me. I am not a developer. I did go to that other page but not sure how to begin or what else I need to know to do this. There are no instructions. What type of button would I be creating to use this feature? I would really appreciate info such as Content Source, Behavior, etc. Thanks! 
Abhishek BansalAbhishek Bansal
Hi,

Please create this class in your org:
public class EXT_AccExtension {
	public String accountId;
	public EXT_AccExtension(ApexPages.StandardController stdController) {
		accountId = (Account)stdController.getRecord().id;
	}
	
	public PageReference redirectToAccount() {
		return new PageReference('/'+accountId);
	}
}
Now add the below VF page:
<apex:page standardController="Account" extensions="EXT_AccExtension" action="{!redirectToAccount}">
</apex:page>
Now change the content source of your button to this new VF page. It will simply refresh the page and return to the same account.
Let me know if you face any issue with this.

Thanks,
Abhishek Bansal.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Phone: +917357512102
KPJSKPJS

Thank you, Abhishek. Getting this error when I try to save the class: 

Error: Compile Error: Incompatible types since an instance of Id is never an instance of Account at line 4 column 21

 

Abhishek BansalAbhishek Bansal
Hi,

Please find the updated class below:
public class EXT_AccExtension {
	public String accountId;
	public EXT_AccExtension(ApexPages.StandardController stdController) {
		Account acc = (Account)stdController.getRecord();
                accountId = acc.Id;
	}
	
	public PageReference redirectToAccount() {
		return new PageReference('/'+accountId);
	}
}

Let me know if you still face any issues.

Thanks,
Abhishek Bansal.
Karen Spence 10Karen Spence 10
Thank you so much, Abhishek. This works so well! Just what I needed. You wouldn't want to provide me the code for the test class too, eh? 0 code coverage. This will never deploy. Thanks!
Abhishek BansalAbhishek Bansal
Please find the test class below:
@isTest
public class AccExtenstionTestClass {
    
static testMethod void accExtTestMethod() {
        Account a = new Account(Name='testAccount');
        insert a; 
    
        ApexPages.StandardController sc = new ApexPages.StandardController(a);
        EXT_AccExtension testAccExt = new EXT_AccExtension(sc);
		
		testAccExt.redirectToAccount();
    }
}

Please close the question if this works for you.

Thanks,
Abhishek Bansal.
KPJSKPJS
Thank you so much! Just curious - would it be relatively simple to create the same solutino, except to have it do a system save, or after insert, to update a record without the user having to edit and save?