I have a Flow that passes ID from the record on which user launched the Flow from, it could be Account, OPP, or Contact I don't know, I only get a RecordId.

I want to be able to run a SOQL query in Apex Trigger to gather data using that RecordId. For example [SELECT Name Where Id = '12344'] I don't have the From name because it could be any object from where the Flow was launched.

How can I archive that, I tried using FIN[] but that also has a return type but I don't know the type of record it is or the Object.

Please let me know, thanks!

1 Answer 1


You can get the object name from the Id like this

String objectName = theId.getSObjectType().getDescribe().getName();

"theId" refers to an "Id" type variable (not a string). You can cast it from a string like this, Id.valueOf('1234').

Also, you will need to use dynamic SOQL for this. e.g. Database.query('SELECT Name FROM ' + objectName + ' WHERE Id = :theId'); See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .