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 

Lightning Issue - Classic works to Get Parent ID upon creation, Lightning error

 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 highlighted code works in Classic and does not work in Lightning.   I assume it is because the URLs are not the same between Classic and Lightning so getting the record ID from the Return URL no longer works.    Is there a simple fix for this to get the record ID a different way than through the return URL?   

The page is called via a button on either the Lead or Opportunity object.   The at the highlighted text is:  System.StringException: Invalid id: lightningcbrecord-actions?objectApiName=TJC_Products__c&actionName=new&inContextOfRef=1
ShirishaShirisha (Salesforce Developers) 
Hi Jason,

Greetings!

Can you please double check,if the record has parent record value.Also,try this with the same record in classic as well to make sure it has the parent record as well cause the code looks good for me.

Also,please check the below blog for the things to take care when we use them in lightning:

http://xintongzhang.blogspot.com/2016/02/things-to-watch-out-for-when-using.html

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri