• Niklas Hillgren
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
SObjectType objToken = Contact.sobjectType;
Map<String, SObjectField> withPrefix = objToken.getDescribe().fields.getMap();
//check rule is fully populated

Map<String, SObjectField> fields = new Map<String, SObjectField>();
//Create a new map without prefix
for( String key : withPrefix.keySet() ){
    fields.put(key, withPrefix.get(key));
}

System.debug('WITH PREFIX: ' + withPrefix.get('lastname'));
System.debug('WITH PREFIX 2: ' + withPrefix.get('LastName'));
System.debug('WITH PREFIX 2: ' + withPrefix.get('LastNAmE')); //ETC?!

System.debug('WITHOUT PREFIX: ' +fields.get('lastname'));
System.debug('WITHOUT PREFIX 2: ' +fields.get('LastName'));
 

My output to debug is:
WITH PREFIX: LastName
WITH PREFIX 2: LastName
WITH PREFIX 3: LastName
WITHOUT PREFIX: LastName
WITHOUT PREFIX 2: null

How come can it be that the map<String, SobjectField> withPrefix isn't case sensetive????? I cannot understand it

Can anyone answer this?

 

I'm working on integration with the parnter/metadata API. I'm using maven as build tool where I have a dependency to the partner/metadata api using the following package http://mvnrepository.com/artifact/com.force.api (Version 34.0.0).

I'm trying to read the Layout metadata using the following utility method:
public T readMetaDataSync(Class<T> metaDataType, String metaDataName) {
		System.out.println("Fetching metadatatype: " + metaDataType.getSimpleName() + " name: " +metaDataName);
		
		T obj = null;
	    try {
	        ReadResult readResult = sfCredentials.getMetadataConnection().readMetadata(metaDataType.getSimpleName(), new String[] { metaDataName });
	        Metadata[] mdInfo = readResult.getRecords();
	        for (Metadata md : mdInfo) {
	            if (md != null) {
	            	obj = metaDataType.cast(md);
	                
	                return obj;
	            } else {
	                System.out.println("Empty metadata.");
	            }
	        }
	    } catch (ConnectionException ce) {
	        ce.printStackTrace();
	    }
	    
	    return obj;
	}

When the method is run for com.sforce.soap.metadata.Layout.class i get the following output:

Fetching metadatatype: Layout name: Contact-Contact Layout
Empty metadata.
However if I change the metadataconnection to a different Salesforce.org it does work and the Layout metadata for Contact is not null.

If I call the same method using the parameters com.sforce.soap.metadata.Metadata.class and the string "Contact" it works for both orgs.

Does anyone have a hint/tips where i can look to figure it out?
SObjectType objToken = Contact.sobjectType;
Map<String, SObjectField> withPrefix = objToken.getDescribe().fields.getMap();
//check rule is fully populated

Map<String, SObjectField> fields = new Map<String, SObjectField>();
//Create a new map without prefix
for( String key : withPrefix.keySet() ){
    fields.put(key, withPrefix.get(key));
}

System.debug('WITH PREFIX: ' + withPrefix.get('lastname'));
System.debug('WITH PREFIX 2: ' + withPrefix.get('LastName'));
System.debug('WITH PREFIX 2: ' + withPrefix.get('LastNAmE')); //ETC?!

System.debug('WITHOUT PREFIX: ' +fields.get('lastname'));
System.debug('WITHOUT PREFIX 2: ' +fields.get('LastName'));
 

My output to debug is:
WITH PREFIX: LastName
WITH PREFIX 2: LastName
WITH PREFIX 3: LastName
WITHOUT PREFIX: LastName
WITHOUT PREFIX 2: null

How come can it be that the map<String, SobjectField> withPrefix isn't case sensetive????? I cannot understand it

Can anyone answer this?

 

I'm working on integration with the parnter/metadata API. I'm using maven as build tool where I have a dependency to the partner/metadata api using the following package http://mvnrepository.com/artifact/com.force.api (Version 34.0.0).

I'm trying to read the Layout metadata using the following utility method:
public T readMetaDataSync(Class<T> metaDataType, String metaDataName) {
		System.out.println("Fetching metadatatype: " + metaDataType.getSimpleName() + " name: " +metaDataName);
		
		T obj = null;
	    try {
	        ReadResult readResult = sfCredentials.getMetadataConnection().readMetadata(metaDataType.getSimpleName(), new String[] { metaDataName });
	        Metadata[] mdInfo = readResult.getRecords();
	        for (Metadata md : mdInfo) {
	            if (md != null) {
	            	obj = metaDataType.cast(md);
	                
	                return obj;
	            } else {
	                System.out.println("Empty metadata.");
	            }
	        }
	    } catch (ConnectionException ce) {
	        ce.printStackTrace();
	    }
	    
	    return obj;
	}

When the method is run for com.sforce.soap.metadata.Layout.class i get the following output:

Fetching metadatatype: Layout name: Contact-Contact Layout
Empty metadata.
However if I change the metadataconnection to a different Salesforce.org it does work and the Layout metadata for Contact is not null.

If I call the same method using the parameters com.sforce.soap.metadata.Metadata.class and the string "Contact" it works for both orgs.

Does anyone have a hint/tips where i can look to figure it out?