• Mohamed Elgindy
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello. I have the following javascript button I need to convert to a lightning component. I'm running into issues with the Apex class. How do I get the 4 account field values and do the 'if statements'? Once I have those field values, how do I create the Lightning Component controller.js? I've read plenty of articles on this but still can't figure it out, can someone please help me with the acutal code?

Original JavaScript button code - 

var taxID= '{!Account.tax__c}'; 
var accID = '{!Account.Id}'; 
var type = '{!Account.TypeId}'; 
var typeName = '{!Account.TypeName}'; 
if(taxD!=null) 

if(typeName !='Personal'){ 
alert('Post message here.'); 

if(type != '987652930764JKS'){ 
var url= '/apex/VisualForcePage?id=' + accID; 
showSplashView(); 
window.location = url; 

else 

var url= '/apex/VisualForcePage?id=' + accID+'&Personal=true'; 
showSplashView(); 
window.location = url; 


else 

alert('Tax Id required'); 
}

Lightning Component (so far) - 

<aura:component controller="Component_Controller" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:hasSObjectName" access="global">
    <aura:attribute name="tax" type="String"/>
    <aura:attribute name="type" type="String"/>
    <aura:attribute name="typeName" type="String"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div class="slds-p-around--x-small slds-align_absolute-center">
           <h2>Post message here.</h2>
    </div>
    <div style="text-align:center">
    <lightning:button label="OK" onclick="{!c.launch}" class="slds-m-bottom-medium"/>
    </div>
</aura:component>

Lightning controller.js (so far) - 

({ 
    doInit : function(cmp) {

        })
    },
    
    launch : function(component, event, helper){
        //on click of "OK", redirect to visualforce page
        
        var urlEvent = $A.get("e.force:navigateToUrl");
        urlEvent.setParams({"url":"/apex/VisualForcePage?id=" + cmp.get("v.recordId") });
        urlEvent.fire();
    } 
})