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
Sweta Agarwal 12Sweta Agarwal 12 

How to get the Object Name from the record Id

Hi

I have written a apex code to call the API (Mulesoft), In order to record the API response I have created a Log table. When a record is created in the Log table, I need to update the record status of the Object (on which the API call was made) to depending on whether the API call was success or failure. I have written a Flow to achieve this. I am passing the recordId of to the flow and to the APEX code. The issue I am facing while updating the record using the recordId within a Update Record instance, I am not aware which Object the record belongs. As a result I have to expand my flow to include an Update Record for each Object for which I am expecting the API respose.

Is it possible to make the "Object" a variable within the "Update Record" Element in the Flow ?? OR Identify the Object Name from the recordId within the Flow. 
VinayVinay (Salesforce Developers) 
Hi,

Try below.
Id myRecordId = 'a9062I000000Wdzdfd3';
String sObjName = myRecordId.getSObjectType().getDescribe().getName();

Thanks,
Vinay Kumar
Santosh Kumar 348Santosh Kumar 348
Hi Sweta,

You can follow a much generalise approach for updating record by working with sObject and Flow. 
https://www.captechconsulting.com/blogs/set-your-flows-free-use-the-same-flow-on-multiple-objects

Please mark my solution as the best answer if it helps you.

Regards,
Santosh Kumar