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
mikumiku 

How to know the sobject type according to the record Id

I create a task which whoid has a value to attach to a record .

If the task status is finished.I want to update the status of the attached record.

but how can I get the sobject type.only I konw is a Id.

Any suggestions would be greatly appreciated.Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Here is the sample code to find out this :

 

http://www.iowntech.com/?p=204

 

But do visit the comments on the blog.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Shashikant SharmaShashikant Sharma

The id will have first three digits as Key Prefix , like for Account '001' , so get a substring fromID for Key

Step1:

String strID = '001ki0000000KIY';

String key = Split(0 , 3);

Step2:

//Do a Global descibe , and create map of all the object key Prefix

Step3:

Check in map which objects key matches

Ankit AroraAnkit Arora

Here is the sample code to find out this :

 

http://www.iowntech.com/?p=204

 

But do visit the comments on the blog.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
mikumiku

Thanks It really fix my issue