Posts

Showing posts with the label ID

Obtain the name of the SObject from a given record ID

In Apex, you can obtain the name of the SObject from a given record ID using the getSObjectType () method provided by the Id class. Example Id recordId = '001XXXXXXXXXXXX'; // Replace this with the actual record ID // Get the SObject type from the record ID Schema.SObjectType sObjectType = recordId.getSObjectType(); // Get the name of the SObject String sObjectName = sObjectType.getDescribe().getName(); System.debug('SObject Name: ' + sObjectName); In this example: recordId.getSObjectType() returns the Schema.SObjectType of the object associated with the record ID. sObjectType.getDescribe().getName() retrieves the name of the SObject. This approach allows you to dynamically determine the SObject name from a record ID in your Apex code.

Retrieve current record id in salesforce

To get the current record ID in Salesforce Visualforce, you can use the Id parameter in the URL or leverage standard controllers. Here are two common methods to accomplish this: Using the Id Parameter in the URL: In Visualforce, you can access the current record's ID using the Id parameter in the URL. This method is commonly used when creating custom pages or links. <apex:page standardController="Account">     <h1> Account Record ID: {!$CurrentPage.parameters.Id}</h1> </apex:page> In this example, {!$CurrentPage.parameters.Id} retrieves the ID from the URL. Using Standard Controllers : If you're using a standard controller in your Visualforce page, you can directly reference the record ID using the Id property of the standard controller. <apex:page standardController="Account">     <h1>Record ID: {! Account.Id}</h1> </apex:page> In this example, {! Account.Id} retrieves the ID of the current record from the st...