0

I have to convert many javascript buttons into Lightning Action to open VF Page. Below is an example of a button on the Account record page.

if( (accStatus != "Active" && accStatus != "Suspended") || openOpps > 0) {
var reasonWhy = '';    
if (accStatus != "Active" && accStatus != "Suspended") {
reasonWhy = 'Account Status is not Active or Suspended. ';
} else if (openOpps > 0) {
reasonWhy = 'There are open Opportunities associated to this Account.';
}    
alert('This Account cannot be closed: ' + reasonWhy);    
}
else {
var theUrl = '/apex/CloseActiveAccount?id={!Account.Id}';

No luck with Lightning converter that recommends a manual conversion. I have no problem with the redirect to url in the Aura component but do not really know where and how to manage the validations and messages (APEX controller, javascript controller, helper...). Thanks in advance for your help. Sylvie

0

Client side validation and Server side validation both have advantage and dis-advantage.

Client-side validation is responsive in terms of user experience but when you see the security concern, you would like to do server-side validation too when required because you can protect against the malicious user, who can easily bypass your JavaScript and submit dangerous input to the server.

You need to also keep in mind that server-side validation will impact the performance.

Coming to your button, Anyhow you have to call the apex method as you will need the account detail in your lightning component controller. Once you get the account field values, You can show the message and navigate to URL in Aura Component controller.

To show the message:-

  1. You can use a toast to show your message
  2. You can show message directly on screen with using slds
  3. You can use notification library

To navigate to URL:-

  1. You can use navigation service in Aura Components.
  2. You can use force:navigatetourl

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.