Sample Code:
Visualforce page:
Apex: Controller:
Output:
Visualforce page:
- <apex:page Controller="sample" sidebar="false" >
- <apex:form >
- <apex:pageblock id="pg" >
- <apex:pageblockSection >
- <apex:pageBlockSectionItem >Record Id</apex:pageBlockSectionItem>
- <apex:pageblockSectionItem ><apex:inputtext value="{!recId}" /></apex:pageblockSectionItem>
- </apex:pageblockSection>
- <apex:pageBlockButtons >
- <apex:commandButton value="Find" action="{!find}" reRender="pg"/>
- </apex:pageBlockButtons>
- <apex:outputText >The object type is : {!objType}</apex:outputText>
- </apex:pageblock>
- </apex:form>
- </apex:page>
Apex: Controller:
- public with sharing class sample {
- public Id recId {get;set;}
- public Schema.SObjectType objType {get;set;}
- public void find() {
- objType = recId.getSobjectType();
- System.debug('Object Type is ' + objType);
- }
- }
Output:
thanks a lot
ReplyDeleteId myId = 'aKZ340000004C97';
ReplyDelete// To retrieve the API Name.
System.debug('Api Name' + myId.getSobjectType().getDescribe().getName());
// To retrieve the Label.
System.debug('Label' + myId.getSobjectType().getDescribe().getLabel());
Thanks Ayan
Delete