Finding the ID of a Salesforce Global Value Set

半世苍凉 提交于 2019-12-10 11:59:52

问题


I'm attempting to write an APEX class that will add items to a global valueset, but in order to do so I need to know the ID of the global value set. Is there a way to find the ID of the global valueset (through APEX, not by looking at the URL) that a picklist field is using? Ideally I'd be able to do something similar to:

Case.picklistField__c.getdescribe();

and get a response that includes the ID of the global value set that it uses - that way I can then use my the metadataAPI to update the values.

Alternatively if I could find the global valueset by name I could use that with the metadata api as a work around.

UPDATE: Was able to get this to work using Eyescreams suggestion with the tooling API - full implementation:

    String gvsName = 'TestValueSet'; //name of the global valueset you want the Id for goes here

    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
    req.setHeader('Content-Type', 'application/json');      
    req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/query/?q=select+id+from+globalvalueset+Where+developername='+gvsName);
    req.setMethod('GET');
    Http httpreq = new Http();
    HttpResponse res  = httpreq.send(req);
    system.debug(res.getBody()); 

回答1:


SELECT Id, FullName, Description
FROM GlobalValueSet

But it's not available in straight Apex queries, you'd need Tooling API (meaning a REST callout). You can play with it in Developer Console -> Query Editor, just check the tooling api checkbox on bottom



来源:https://stackoverflow.com/questions/53822044/finding-the-id-of-a-salesforce-global-value-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!