• Newtec
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi,

Does anybody have working code to retrieve and upsert picklist value sets ?

Can't get it to work, this is my current code :
 
private GlobalValueSet readGlobalValueSet(String picklist) throws Exception {
		GlobalValueSet values = new GlobalValueSet();
		


			MetadataConnection metadataConnection = sfmcon.getConnection();
			
			ReadResult readResult = metadataConnection.readMetadata("GlobalValueSet", new String[] {picklist});
			//log.info(readResult.toString());
			Metadata[] mdInfo = readResult.getRecords();
			if (mdInfo.length == 1) {
				values = (GlobalValueSet) mdInfo[0];
			}
			else {
				log.info("None or multiple components");		
			}

		
		return values;
	}

readMetadata returns :

[CustomValue [Metadata  fullName='A02'
]
 color='null'
 _default='false'
 description='null'
 isActive='false'
 label='A02'
]
]

The picklist value is active so i would expect :

[CustomValue [Metadata  fullName='A02'
]
 color='null'
 _default='false'
 description='null'
 isActive='true'
 label='A02'
]
]

Later when i execute the upsert with :
 
MetadataConnection metadataConnection = sfmcon.getConnection();
			SaveResult[] results = metadataConnection.updateMetadata(new Metadata[] {repair});

I get the error output :

Error encountered while updating: Application
Error message: CustomField not found.
Hi,

Trying to change values in a global picklist value set but when reading the metadata the CustomValue object is not filled. We only get the Value itself (label and name) but the isActiven, color ,... fields are not set :

Result :

[ReadResult  records='{[1][GlobalValueSet [Metadata  fullName='Application'
]
 customValue='{[84][CustomValue [Metadata  fullName='A01'
]
 color='null'
 _default='false'
 description='null'
 isActive='false'
 label='null'
]
]

=> This value is certainly active in salesforce.

If we change the CustomValue object to isActive = true, and execute an update to salesforce, this error message is given :

"CustomField not found."

This is the method that reads the metadata of a GlobalValueSet 
 
private GlobalValueSet readGlobalValueSet(String picklist) throws Exception {
		GlobalValueSet affectsVersions = new GlobalValueSet();
		
		try{

			MetadataConnection metadataConnection = sfmcon.getConnection();
			
			ReadResult readResult = metadataConnection.readMetadata("GlobalValueSet", new String[] {picklist});
			//log.info(readResult.toString());
			Metadata[] mdInfo = readResult.getRecords();
			if (mdInfo.length == 1) {
				affectsVersions = (GlobalValueSet) mdInfo[0];
			}
			else {
				log.info("None or multiple components");		
			}
		}
		catch(ConnectionException e){
			e.printStackTrace();
		}
		
		return affectsVersions;
	}
Probably doing something wrong here, don't think it is authorization related as the user has Modify everything rights.

with regards
Hi,

Does anybody have working code to retrieve and upsert picklist value sets ?

Can't get it to work, this is my current code :
 
private GlobalValueSet readGlobalValueSet(String picklist) throws Exception {
		GlobalValueSet values = new GlobalValueSet();
		


			MetadataConnection metadataConnection = sfmcon.getConnection();
			
			ReadResult readResult = metadataConnection.readMetadata("GlobalValueSet", new String[] {picklist});
			//log.info(readResult.toString());
			Metadata[] mdInfo = readResult.getRecords();
			if (mdInfo.length == 1) {
				values = (GlobalValueSet) mdInfo[0];
			}
			else {
				log.info("None or multiple components");		
			}

		
		return values;
	}

readMetadata returns :

[CustomValue [Metadata  fullName='A02'
]
 color='null'
 _default='false'
 description='null'
 isActive='false'
 label='A02'
]
]

The picklist value is active so i would expect :

[CustomValue [Metadata  fullName='A02'
]
 color='null'
 _default='false'
 description='null'
 isActive='true'
 label='A02'
]
]

Later when i execute the upsert with :
 
MetadataConnection metadataConnection = sfmcon.getConnection();
			SaveResult[] results = metadataConnection.updateMetadata(new Metadata[] {repair});

I get the error output :

Error encountered while updating: Application
Error message: CustomField not found.
Hi,

Trying to change values in a global picklist value set but when reading the metadata the CustomValue object is not filled. We only get the Value itself (label and name) but the isActiven, color ,... fields are not set :

Result :

[ReadResult  records='{[1][GlobalValueSet [Metadata  fullName='Application'
]
 customValue='{[84][CustomValue [Metadata  fullName='A01'
]
 color='null'
 _default='false'
 description='null'
 isActive='false'
 label='null'
]
]

=> This value is certainly active in salesforce.

If we change the CustomValue object to isActive = true, and execute an update to salesforce, this error message is given :

"CustomField not found."

This is the method that reads the metadata of a GlobalValueSet 
 
private GlobalValueSet readGlobalValueSet(String picklist) throws Exception {
		GlobalValueSet affectsVersions = new GlobalValueSet();
		
		try{

			MetadataConnection metadataConnection = sfmcon.getConnection();
			
			ReadResult readResult = metadataConnection.readMetadata("GlobalValueSet", new String[] {picklist});
			//log.info(readResult.toString());
			Metadata[] mdInfo = readResult.getRecords();
			if (mdInfo.length == 1) {
				affectsVersions = (GlobalValueSet) mdInfo[0];
			}
			else {
				log.info("None or multiple components");		
			}
		}
		catch(ConnectionException e){
			e.printStackTrace();
		}
		
		return affectsVersions;
	}
Probably doing something wrong here, don't think it is authorization related as the user has Modify everything rights.

with regards