+ Start a Discussion
aswanijagadesh1.397398535585991E12aswanijagadesh1.397398535585991E12 

Dispalying all objects in organization with its keyprefixs ?

Hai friends,
i want to display all objects with its keyprefix values for this i done like this

in controller class:
public class GettingObjectsAndKeyPrifix {
    public List<Schema.SObjectType> gd {get;set;}
    public List<String> objectMap {get;set;}

     Public GettingObjectsAndKeyPrifix(){
        gd= Schema.getGlobalDescribe().Values();
        objectMap = new List<String>();
        for(Schema.SObjectType f : gd)
        {
            objectMap.add(f.getDescribe().getKeyPrefix());
        }
        System.debug('--------- --'+gd);
        System.debug('+++++++++ --'+objectMap.size() );
    }
}

in visual force page:
<apex:page controller="GettingObjectsAndKeyPrifix">
    <!--http://srinivas4sfdc.blogspot.in/2013/12/list-of-salesforce-object-key-prefixes.html-->
   <apex:pageBlock >
   <apex:pageBlockSection >
        <apex:pageBlockTable value="{!objectMap}" var="o">
        <apex:column value="{!o}"></apex:column>
        </apex:pageBlockTable>  
      <apex:pageBlockTable value="{!gd}" var="g">
    <apex:column value="{!g}"></apex:column>
    </apex:pageBlockTable>
  
    </apex:pageBlockSection>
   
     </apex:pageBlock>
   
</apex:page>

here output is comming ,but i want output like

account--001
Note-002
like this how can i please help.

i want ouput like this in url
http://srinivas4sfdc.blogspot.in/2013/12/list-of-salesforce-object-key-prefixes.html
Best Answer chosen by aswanijagadesh1.397398535585991E12
Abhinav GuptaAbhinav Gupta
#1 Try passing list<Schema.SObjectType> to UI

I doubt it might fail because Schema.SObjectType might not be serialisable

#2 Create a wrapper class for capturing required details

Here is some code what you can take forward

Apex

public class gettingObjectsAndKeyPrefix {

 	public class SObjectInfo {
 		public String prefix {get;set;}
 		public String name {get;set;}


 	}

	public List<SObjectInfo> objectMap {get;set;}

    public GettingObjectsAndKeyPrifix(){
        gd= Schema.getGlobalDescribe().Values();
        objectMap = new List<String>();
        for(Schema.SObjectType f : gd)
        {
        	SObjectInfo si = new SObjectInfo();
        	si.prefix = f.getDescribe().getKeyPrefix();
        	si.name = f.getDescribe().getLabel();
            objectMap.add(si);
        }        
    }

}
Visualforce

<apex:pageBlockTable value="{!objectMap}" var="o">
    <apex:column headerValue="Key Prefix" value="{!o.prefix}"></apex:column>
    <apex:column headerValue="Object Type" value="{!o.name}"></apex:column>
</apex:pageBlockTable>



All Answers

Abhinav GuptaAbhinav Gupta
You need to change one line i.e.

objectMap.add(f.getDescribe().getLabel() + '--' + f.getDescribe().getKeyPrefix());

aswanijagadesh1.397398535585991E12aswanijagadesh1.397398535585991E12
hai Abhinav Gupta,
it is working fine,but i want output  in two columns not in single column

like this in this url
http://srinivas4sfdc.blogspot.in/2013/12/list-of-salesforce-object-key-prefixes.html

Abhinav GuptaAbhinav Gupta
#1 Try passing list<Schema.SObjectType> to UI

I doubt it might fail because Schema.SObjectType might not be serialisable

#2 Create a wrapper class for capturing required details

Here is some code what you can take forward

Apex

public class gettingObjectsAndKeyPrefix {

 	public class SObjectInfo {
 		public String prefix {get;set;}
 		public String name {get;set;}


 	}

	public List<SObjectInfo> objectMap {get;set;}

    public GettingObjectsAndKeyPrifix(){
        gd= Schema.getGlobalDescribe().Values();
        objectMap = new List<String>();
        for(Schema.SObjectType f : gd)
        {
        	SObjectInfo si = new SObjectInfo();
        	si.prefix = f.getDescribe().getKeyPrefix();
        	si.name = f.getDescribe().getLabel();
            objectMap.add(si);
        }        
    }

}
Visualforce

<apex:pageBlockTable value="{!objectMap}" var="o">
    <apex:column headerValue="Key Prefix" value="{!o.prefix}"></apex:column>
    <apex:column headerValue="Object Type" value="{!o.name}"></apex:column>
</apex:pageBlockTable>



This was selected as the best answer
aswanijagadesh1.397398535585991E12aswanijagadesh1.397398535585991E12

it gives an error Error: Compile Error: Illegal assignment from LIST<String> to LIST<GettingObjectsAndKeyPrifix.SObjectInfo> at line 13 column 9

like this i wrote:

 public class GettingObjectsAndKeyPrifix{
    public List<Schema.SObjectType> gd {get;set;}
    public class SObjectInfo {
        public string prefix {get;set;}
        public string name {get;set;}
    }

    public List<SObjectInfo> objectMap {get;set;}

    public GettingObjectsAndKeyPrifix(){

        gd= Schema.getGlobalDescribe().Values();
        objectMap = new List<String>();

        for(Schema.SObjectType f : gd)
 
        {
         SObjectInfo si = new SObjectInfo();
          si.prefix = f.getDescribe().getKeyPrefix();
          si.name = f.getDescribe().getLabel();
          objectMap.add(si);
       }        
  }

}

will you please tell me ,in that format we will get the output or not

aswanijagadesh1.397398535585991E12aswanijagadesh1.397398535585991E12
sorry , chanhe this :objectMap=new List<SObjectInfo>();
it is working thank you so much.