Loading

Usage and Behavior of the inContextOfRef Variable

Julkaisupäivä: Feb 12, 2026
Kuvaus

What is inContextOfRef?

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.

Common Attempted Use Cases

Developers have tried using inContextOfRef in the following scenarios:

  • In Apex: To dynamically determine the parent record context.
  • In Lightning Web Components (LWC) or Visualforce pages: To resolve and retrieve the record's ID and default values from the URL based on the current context.
  • As part of a custom solution: To simplify complex relationship queries and enhance flexibility in retrieving related records.

Example Scenario

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:

  • Quick Actions
  • Related Lists
  • Custom Buttons

To prevent this instability, developers should use Salesforce's supported URL parameter handling methods instead.

Ratkaisu

Why inContextOfRef Should Not Be Used

The 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:

  • Its behavior can change without notice in future releases.
  • It may throw undefined exceptions in certain contexts.
  • Salesforce Support cannot assist with issues related to its use.
  • Code using this variable may break during Salesforce platform upgrades.

Recommended Alternatives

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.

Knowledge-artikkelin numero

003817198

 
Ladataan
Salesforce Help | Article