I need help please, I'm trying to get the ID of the current page. from a page of a community in salesforce, but every time I reload the page to get the ID this arrives undefined, the URL that I am occupying is something like this: someurl / s /? idLead = 00QQ000000En8pgG6D thanks a lot!

    public Static Lead getLead(String recordId){
        Lead infoUser = new Lead(); 
        System.debug('ID del usuario actual: '+ recordId );
        infoUser = [SELECT FirstName, LastName
                    FROM Lead  WHERE Id = :recordId];
        return infoUser;

<aura:component  implements="flexipage:availableForAllPageTypes,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="ctrlWeddingForm">
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="infolead" type="Lead"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


        <div class="slds-grid slds-wrap slds-form-element">
            <div class="slds-col slds-size_1-of-1 slds-large-size_6-of-12">
                <label for="disabledInput" class="col-sm-4 control-label titulo_datos">Nombre:</label>

            <div class="slds-col slds-size_1-of-1 slds-large-size_6-of-12">
                <p id="" disabled="true" class="slds-input contenido_datos" type="text" value="">{!v.infolead.FirstName}</p>



    doInit : function(component, event, helper) {
        helper.getinfoLead(component, event, helper);


    getinfoLead : function(component, event, helper) {

        var action = component.get("c.getLead");
            "recordId" : component.get("v.recordId")

        action.setCallback(this, function(a) {
            if (a.getState() === "SUCCESS") {
                var infolead = a.getReturnValue();
                component.set("v.leadInfo", infolead);
            } else if (a.getState() === "ERROR") {
                console.log("Ocurrio un error");
| improve this question | | | | |
  • is your component on an object record page? it doent look like it - component.get("v.recordId") will only work on record pages in communities – glls Apr 26 '19 at 14:40
  • No Sir, my component is not an object record page, the force:hasRecordId only works for a object record page? thanks for your help – Sergio Sabido Apr 26 '19 at 14:44

By the looks of what you have shared, the reason why component.get("v.recordId") is undefined is most likely due to the fact that this only words on object record pages in communities.

If you are not on an object record page, you will need to fetch the id from your URL by other means.

| improve this answer | | | | |
  • To solve the problem, what I have done is get the ID through javascript, the problem is that there is no way to pass the variable to the apex class var url_string = document.location.href var url = new URL(url_string); var idlead = url.searchParams.get("idLead"); console.log(idlead) – Sergio Sabido Apr 26 '19 at 16:19

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.