I try to programmatically get the fields and their types of all Salesforce Objects (including custom ones). But some Types don't seem to exist.
For this i use the force.com wsc version 32.0.0, the partner wsdl and the metadata wsdl.
public FileProperties[] listMetadata(String type){
FileProperties[] props = null;
ListMetadataQuery query = new ListMetadataQuery();
query.setType(type);
try {
props = connector.getConnection().listMetadata(new ListMetadataQuery[]{query}, API_VERSION);
} catch (ConnectionException e) {
LOG.warn("Exception occured while trying to list Metadata for {}.", type, e);
}
return props;
}
I grab the list of Metadata (the parameter is 'CustomObject'), then I try to get each object separately to get the fields.
public CustomObject getObjectByName(String name) {
CustomObject object = new CustomObject();
try {
ReadResult result = connector.getConnection().readMetadata("CustomObject", new String[] { name });
Metadata[] metadata = result.getRecords();
object = (CustomObject) metadata[0];
} catch (ConnectionException e) {
LOG.warn("ConnectionException occured while trying to read Metadata. Custom Object Name: {}", name, e);
object.setFullName(name);
}
return object;
}
listing objects:
public void getFieldsForObjects() {
System.err.println("=============== object with fields ===============");
FileProperties[] props = reader.listMetadata("CustomObject");
for (FileProperties prop : props) {
CustomObject o = null;
o = reader.getObjectByName(prop.getFullName());
printObject(o);
}
}
and then I get:
Opportunity {
AccountId : Lookup
Amount : null
CampaignId : Lookup
CloseDate : null
ContractId : Lookup
CurrentGenerators__c : Text
DeliveryInstallationStatus__c : Picklist
Description : null
ExpectedRevenue : null
IsPrivate : null
LeadSource : Picklist
MainCompetitors__c : Text
Name : null
NextStep : null
OrderNumber__c : Text
OwnerId : Lookup
Probability : null
StageName : Picklist
TotalOpportunityQuantity : null
TrackingNumber__c : Text
Type : Picklist
}
Can anyone tell why it is like that and what to do? I already checked both wsdls and they don't seem to have the types declared. Missing types are currency, percent, and some others.