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
Rashmi27Rashmi27 

How to get object instance from URL like https://cs17.salesforce.com/01pg00000004s2u

How to get object instance from URL like https://cs17.salesforce.com/01pg00000004s2u  without using  following way

 

Apexpages.currentPage().getHeaders().get('referer').right(15);

 

Because I am unable to execute  the unit test cases.

 

Is there any other way help appreciated !.........

 

 

Cheers!..

 

 

Dhaval PanchalDhaval Panchal
ApexPages.currentPage().getParameters().get('Id')
Satish_SFDCSatish_SFDC
apexpages.currentpage().getparameters().get('id')

Regards,
Satish Kumar
bob_buzzardbob_buzzard

How will either of these get the record id from the end of the URL?  Both of these suggestions expect an id parameter on the URL, which the OP has clearly not included.

 

If its just to make the unit tests work, I would use the Test.isRunningTest method to take some different action. Something like:

 

Id recId;

if (Test.isRunningTest())
{
  // do something different here.  You could always the the unit test
  // set the value of recId if you provide a private setter for it.
}
else
{
   recId=Apexpages.currentPage().getHeaders().get('referer').right(15);
}