The variable inContextOfRef is an undocumented variable that some developers use. It retrieves URL parameters and determines record context in Salesforce. However, it is not officially supported by Salesforce and should not be used in production code.
Developers have tried using inContextOfRef in the following scenarios:
A developer building a custom Visualforce page needs to determine which Account record a user viewed before navigating to the page. They discover the inContextOfRef variable in an old code sample and implement it to retrieve the parent Account ID.
Initially, the solution passes testing. However, users later report sporadic errors where the variable returns undefined, causing the page to crash. This failure occurs because inContextOfRef is not officially supported and behaves inconsistently across different navigation contexts, such as:
To prevent this instability, developers should use Salesforce's supported URL parameter handling methods instead.
inContextOfRef Should Not Be UsedThe use of inContextOfRef may lead to inconsistent results in dynamic environments, such as custom Lightning components or Visualforce pages. This variable is undocumented and unsupported by Salesforce. Consider the following points:
Instead of using inContextOfRef, developers should use the following supported approaches:
For Lightning Web Components (LWC)
Use the @api decorator to receive the record ID from the parent component or use the getRecord wire adapter to fetch record details.
Example:
import { LightningElement, api } from 'lwc';
export class MyComponent extends LightningElement {
@api recordId; // Automatically populated when component is placed on a record page
}
For Visualforce Pages
Use the $CurrentPage.parameters global variable or standard controller methods to access URL parameters in a supported way.
Example:
String recordId = ApexPages.currentPage().getParameters().get('id');
For Apex Controllers
Use the ApexPages.currentPage().getParameters() method to retrieve URL parameters.
Example:
public class MyController {
public Id getRecordId() {
String idParam = ApexPages.currentPage().getParameters().get('id');
if (String.isNotBlank(idParam)) {
return Id.valueOf(idParam);
}
return null;
}
}
These supported methods provide reliable and documented ways to access record context and URL parameters across all Salesforce environments.
003817198

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.