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
Jason WenigJason Wenig 

Visual Force Page Object ID in Lightning

Long ago, consultants built a visual force page that upon a newly created custom object, sets the lookup field object based on the current page.   The custom object can be linked to a lead or to an opportunity.

Existing code:
String pId = controller.getId();               
        
        if (pId == null)
        {
            oTJC_Product = new TJC_Products__c();
            
            if (ApexPages.currentPage().getParameters().get('retURL') != null)
            {
                Id pageId = ApexPages.currentPage().getParameters().get('retURL').Replace('/','');
                if (pageId.getSObjectType().getDescribe().getName() == 'Lead')
                {
                    oLead = [select id, name from Lead where id =:pageId];
                    oTJC_Product.Lead__c = pageId;
                }
                else
                {
                    oOpportunity = [select id, name from Opportunity where id =:pageId];
                    oTJC_Product.Opportunity__c = pageId;
                }
            }

The above code works in classic as the URL had the ID on the end of the return URL BUT in lightning, the URL is different now and doesn't appear to contain the ID at all.    

I'm not sure what the answer to replace ApexPages.currentPage().getParameters().get('retURL') in Lightning is but this should not be so difficult to do. 

Apexpages.currentpage().getParameters().get('vfRetURLInSFX') does return a URL in lightning but the URL can't even be parsed to get an ID from the URL.

Please help.