Thursday, May 17, 2012

Salesforce - metadata gotchas

Found a nice gotcha in salesforce today. If you use the metadata API, and create a new field, you have to stay connected until it is complete. If you create a field, and don't check on it's status until it is done, your field will be gone. I'm assuming this is some sort of self-protection mechanism of salesfoce, who knows:

You have to to some something like this: (Assuming you are using the sf-connector-api)

 while (resultList.get(0).state.value() == 'InProgress') {
                sleep(500)
                resultList = metadataConn.checkStatus(tempList)
                if (resultList.get(0).state.value() == 'Error') {
                    // gather errors
                    throw new MetadataServiceException("Error creating custom field")
                }
            }

Also another nugget I found - you can only create 10 fields at a time. If you want to create more than that, you need to break  your list into chunks of 10. Any yes, you must check until they are successful if you want them to show up ;)

No comments: