We know there are two types of record-id are present in salesforce (18 digit -- Case Insensitive,15 digit -- Case Sensitive). Only 3 digit of ids represent object type .The following is a list of the Salesforce Standard Object ID prefixes
Object
|
Prefix
|
Account
|
001
|
NOTE
|
002
|
Contact
|
003
|
User
|
005
|
Opportunity
|
006
|
Activity
|
007
|
Please check below post for more detail
If you want to get the Prefix of any object . Please try below code.
String keyPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
System.debug('PREFIX--' + keyPrefix );
If you want to get the Object Name from RecordId then please try below code.
public class SchemaGlobalDescribeToGetObjectName
{
public static String findObjectNameFromRecordIdPrefix(String recordIdOrPrefix)
{
String objectName = '';
try
{
String IdPrefix = String.valueOf(recordIdOrPrefix).substring(0,3);
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType stype : gd.values())
{
Schema.DescribeSObjectResult r = stype.getDescribe();
String prefix = r.getKeyPrefix();
if(prefix!=null && prefix.equals(IdPrefix))
{
objectName = r.getName();
System.debug('Object Name! ' + objectName);
break;
}
}
}catch(Exception e){
System.debug(e);
}
return objectName;
}
}
If you want to Get the Object prefix by Workbench then please try below step :-
The easiest way to find out which key prefix maps to which object is by using a tool like the workbench . After you log into workbench, go to and pick an object from the pick list.
Step 1 :- Login in to Workbench
Step 2:- Info > Standard & Custom Objects
Step 3:- Then select your object
Thanks
Amit Chaudhary




1) isExecuting Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or anexecuteanonymous() API call.
2) isInsert Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or theAPI.
3) isUpdate Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or theAPI.
4) isDelete Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or theAPI.
5) isBefore Returns true if this trigger was fired before any record was saved.
6) isAfter Returns true if this trigger was fired after all records were saved.
7) isUndelete Returns true if this trigger was fired after a record is recovered from the Recycle Bin (that is, after an undelete operation from the Salesforce user interface, Apex, or the API.)
8) new Returns a list of the new versions of the sObject records.Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.
9) newMap A map of IDs to the new versions of the sObject records. Note that this map is only available in before update, after insert, and after update triggers.
10) old Returns a list of the old versions of the sObject records.Note that this sObject list is only available in update and delete triggers.
11) oldMap A map of IDs to the old versions of the sObject records.Note that this map is only available in update and delete triggers.
12) size The total number of records in a trigger invocation, both old and new.
Sample trigger
trigger AccountTrigger on Account( after insert, after update, before insert, before update) { AccountTriggerHandler handler = new AccountTriggerHandler(Trigger.isExecuting, Trigger.size); if( Trigger.isInsert ) { if(Trigger.isBefore) { handler.OnBeforeInsert(trigger.New); } else { handler.OnAfterInsert(trigger.New); } } else if ( Trigger.isUpdate ) { if(Trigger.isBefore) { handler.OnBeforeUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap); } else { handler.OnAfterUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap); } } }Create one Trigger Handler Class
Create one Trigger Action Class
public without sharing class AccountActions { public static void updateContact ( List<Account> newAccount) { // Add your logic here } }SourcePlease check below post for full example of Trigger
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Please let us know if this will help you.