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
Sam AroraSam Arora 

how to get sobject and Id in lightning components controller

<aura:component implements="force:hasRecordId,force:hasSObjectName" access= "global" >
    <ltng:require styles="/resource/SLDS231/assets/styles/salesforce-lightning-design-system-ltng.css"/>
    
    <aura:attribute name="recordId" type="String" default="{!recordId}"/>
    <aura:attribute name="sObjectName" type="String" default="{!sObjectName}"/>
    <aura:handler name="init" value="{!this}" action="{!c.gotoURL}"/>

      <h1>
        Hello Geeky developers :)
        <br/>
        I am from lightning.
    </h1>
    <br/>
    <!-- recordId and sObjectName attributes will be available for use.-->
    <h2> This is the record id : {!v.recordId}</h2>
    <br/>
    <h2> This is the SObject name of the current record : {!V.sObjectName }</h2>
</aura:component>



({
    gotoURL : function(component, event, helper) {
         
        var urlEvent = $A.get("e.force:navigateToURL");
        var PG_ID = component.get("v.recordId");
        var PG_SOBJ = component.get("v.sObjectName");
         
        action.setParams({ 
            "P_ID": PG_ID
        });
         action.setParams({ 
            "P_sob": PG_SOBJ
        });
        
    }
})
Shiva RajendranShiva Rajendran
Hello Shanky Munjal,
You must have a component which implements force:hasRecordId.
<aura:attribute name="recordId" type="String" />
You must use $A.get("e.force:navigateToSObject") 
Also one point to note,you must view the component in Salesforce 1 view in browser by clicking inspect element or view it directly in mobile salesforce 1 to get the expected result.
Else $A.get("e.force:navigateToSObject") would return null.

Let me know if you need further help.

Thanks and Regards,
Shiva RV