+ Start a Discussion
Smriti Kumari (Shumpy)Smriti Kumari (Shumpy) 

How to get the recordId from the detail page of any sObject in Lightning Experience!

I have a requirement where I need to dynamically get the RecordId in a VF page which is launched on click of a global action in sObject's detail page. As this sObject will be dynamic, I can't use a standard controller. The VF page opens up in an iFrame which doesn't get the Id from the detail page link. I tried URL methods for JavaScript call but with no success.

Does anyone have any idea upon how to retrieve this in Lightning Experience?
This functionality was completed well in SF classic via a button.
RecordId doesn't come in the iFrame.
Best Answer chosen by Smriti Kumari (Shumpy)
Smriti Kumari (Shumpy)Smriti Kumari (Shumpy)
To get a record Id we need to implement the force:hasRecordId interface.
Once done, we can access the record id by:
{!v.recordId}

http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/rn_lightning_components.htm

All Answers

salesforce mesalesforce me
Hi Kumari can u check it once this code...
<apex:page standardController="Case" extensions="CaseEdit_ControllerExtension" title="Case Edit" tabStyle="Case">
    <apex:form id="form">
        <apex:pageBlock title="Case Edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!doSave}" value="Save" />
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Case Information">
                <apex:inputField value="{!Case.Summary}" required="true" />
                <apex:pageBlockSectionItem>
                    <apex:outputLabel for="productList" value="{!$ObjectType.Case.fields.Product__c.label}" />
                    <apex:actionRegion>
                        <apex:selectList value="{!product}" title="Product" size="1" id="products">
                            <apex:selectOptions value="{!productList}" />
                            <apex:actionSupport event="onchange" rerender="versions" />
                        </apex:selectList>
                    </apex:actionRegion>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel for="versions" value="{!$ObjectType.Case.fields.Version__c.label}" />
                    <apex:actionRegion>
                        <apex:selectList value="{!version}" title="Version" size="1" id="versions">
                            <apex:selectOptions value="{!versionList}" />
                        </apex:selectList>
                    </apex:actionRegion>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public with sharing class ProductUtils {
    static public List<Product__c> getAllProducts(Boolean includeEOL) {
        //This is done since the formula field cannot return a boolean
        Integer currentlySupported = (includeEOL) ? 0 : 1;

        return [
            select Name
            from Product__c
            where Currently_Supported__c >= :currentlySupported
            order by Name
        ];
    }

    public static List<Product__c> getAllProducts() {
        return getAllProducts(false);
    }

    public static List<Version__c> getAllVersions(Id productId, Boolean includeEOL) {
        Integer currentlySupported = (includeEOL) ? 0 : 1;

        return [
            select Name,
                Product__c
            from Version__c
            where Currently_Supported__c >= :currentlySupported and
                Product__c = :productId
            order by Name
        ];
    }

    public static List<Version__c> getAllVersions(Id productId) {
        return getAllVersions(productId, false);
    }
}
Smriti Kumari (Shumpy)Smriti Kumari (Shumpy)
Hi 
salesforce me,
Appreciate your feedback. But FYI I can't use a standard controller as Id has to be fetched dynamically. The VF page opens up in an iFrame which doesn't get the Id from the detail page. The functionality mentioned above has already been achieved via a custom button in Salesforce Classic (for the same VF page) but the Lightning Experience doesn't give the Id in the iFrame
Abhiram Sheshadri 9Abhiram Sheshadri 9

Hi Smriti,

Did you find the solution for your problem? I am also facing the same issue. If you have solved it, can you please explain the solution?

Thanks,
Abhiram

Smriti Kumari (Shumpy)Smriti Kumari (Shumpy)
Hi @Abhiram Sheshadri 9,

I didn't find a solution to it yet!
 
Smriti Kumari (Shumpy)Smriti Kumari (Shumpy)
To get a record Id we need to implement the force:hasRecordId interface.
Once done, we can access the record id by:
{!v.recordId}

http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/rn_lightning_components.htm
This was selected as the best answer