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
Nizam SaifiNizam Saifi 

How to get id from salesforce community URL

Hi All, I want to get id from parameter in salesforce community into apex controller but not able to get it. I tried to use ApexPages.currentPage().getParameters().get('id') but it is not working 
C LC L
Hi Nizam,

If you're using API version 43 and up, you can implement lightning:isUrlAddressable interface and use pageReference attribute. A good example of this was posted here (https://salesforce.stackexchange.com/questions/165650/getting-the-url-parameter-into-lightning-component-using-the-paramname-exp). Below is a recap of the example provided:
 
Example - Component Assume url is https://<instance>.lightning.force.com/lightning/cmp/<namespace>__componentName?testAttribute=abc

Lightning Component:
<aura:component implements="lightning:isUrlAddressable">
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" description="Handler for valueInit event fired when the component has been initialised"/>
        {!v.pageReference.state.testAttribute}
</aura:component>


Controller:
({
    doInit : function(component, event, helper) {
        console.log(component.get("v.pageReference").state.testAttribute);
    }
})


Page Reference Types:  https://developer.salesforce.com/docs/atlas.en.us.214.0.lightning.meta/lightning/components_navigation_page_definitions.htm