Get list of Key Prefix of Sobject in Salesforce
Requirement: Show the list of Key Prefix of Sobject in salesforce
Solution:
Class Code:
public class populateObjectsAndKeyPrefixController {
public List<Schema.SObjectType> lstofSType {get;set;}
public List<SObjectInfo> lstofSobject {get;set;}
public class SObjectInfo {
public String prefix {get;set;}
public String name {get;set;}
}
public gettingObjectsAndKeyPrefix(){
lstofSType = Schema.getGlobalDescribe().Values();
lstofSobject = new List<SObjectInfo>();
for(Schema.SObjectType f : lstofSType )
{
SObjectInfo sobjectinfo = new SObjectInfo();
sobjectinfo.prefix = f.getDescribe().getKeyPrefix();
sobjectinfo.name = f.getDescribe().getLabel();
lstofSobject.add(SObjectInfo);
}
}
}
VF Page Code
<apex:page controller="populateObjectsAndKeyPrefixController " showHeader="false">
<apex:form >
<apex:pageBlock title="Objects Prefix Details" >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!lstofSobject }" var="objMap">
<apex:column headerValue="Key Prefix" value="{!objMap.prefix}" ></apex:column> <!-- rendered="{!if(objMap.prefix !=null,true,false)}" -->
<apex:column headerValue="Object Type" value="{!objMap.name}" ></apex:column> <!-- rendered="{!if(objMap.prefix !=null,true,false)}" -->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Solution:
Class Code:
public class populateObjectsAndKeyPrefixController {
public List<Schema.SObjectType> lstofSType {get;set;}
public List<SObjectInfo> lstofSobject {get;set;}
public class SObjectInfo {
public String prefix {get;set;}
public String name {get;set;}
}
public gettingObjectsAndKeyPrefix(){
lstofSType = Schema.getGlobalDescribe().Values();
lstofSobject = new List<SObjectInfo>();
for(Schema.SObjectType f : lstofSType )
{
SObjectInfo sobjectinfo = new SObjectInfo();
sobjectinfo.prefix = f.getDescribe().getKeyPrefix();
sobjectinfo.name = f.getDescribe().getLabel();
lstofSobject.add(SObjectInfo);
}
}
}
VF Page Code
<apex:page controller="populateObjectsAndKeyPrefixController " showHeader="false">
<apex:form >
<apex:pageBlock title="Objects Prefix Details" >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!lstofSobject }" var="objMap">
<apex:column headerValue="Key Prefix" value="{!objMap.prefix}" ></apex:column> <!-- rendered="{!if(objMap.prefix !=null,true,false)}" -->
<apex:column headerValue="Object Type" value="{!objMap.name}" ></apex:column> <!-- rendered="{!if(objMap.prefix !=null,true,false)}" -->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Sumit Shukla
Comments
Post a Comment