0

This is my lex controller

({
    handleClick : function(component, event, helper) {

        var recId = component.get('v.recordId');
        var retURL = component.get('v.pdf');
        retURL = window.open("apex/Letter?recordId="+recordID);

    }
})

Lex component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
   <lightning:button label="PDF" onclick ="{!c.handleClick}"/>
   <aura:attribute name="recordId" type="String"/> 
</aura:component>

when I have clicked on PDF button on my record page I got a message URL doesn't exist.

Someone in my org has deleted my controller, I have written the same code previously which used to work, now it's not working

1 Answer 1

3

Three things.

First, don't specify recordId when you use force:hasRecordId. If you don't define it exactly correct, you can end up causing bugs.

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
   <lightning:button label="PDF" onclick ="{!c.handleClick}"/>
</aura:component>

Second, always specify a leading forward slash in the URL or you'll end up creating a "relative URL"; you'll end up with the wrong URL.

Third, make sure you type the correct variable name, and remember it is case sensitive.

({
    handleClick : function(component, event, helper) {
        var recId = component.get('v.recordId');
        window.open("/apex/Letter?recordId="+recId);
    }
})
3
  • after WI18 edition, the recordID interface is not working hence I have added the recordID attribute and defined it in the controller, but on the button click I got an error 'recID' not defined. But the recordID was defined correctly
    – sf123
    Jul 28, 2018 at 9:37
  • @sf123 Everything in Lighting is case sensitive. From what I can tell, you're not abiding by those rules.
    – sfdcfox
    Jul 28, 2018 at 9:39
  • Thanks got it. I didn't follow the case-sensitive rule
    – sf123
    Jul 28, 2018 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .