[英]Programatically fetch a list of all Salesforce Objects using apex in Salesforce
我想获取所有 Salesforce 对象的列表。 我找到了这个链接http://wiki.developerforce.com/index.php/Enterprise_Describe_Global
但有一些问题:
1)缺少会话(无效的 session id)为了防止这种情况,我在 url 中附加了 session 密钥,但它也显示没有请求。
错误:内部服务器错误 (500)
2)我在某处找到并添加了 clientId 以及 session header 但再次没有响应。
错误:内部服务器错误 (500)
web 请求的代码示例:
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('POST');
req.setHeader('content-type','text/xml;charset=utf-8');
req.setHeader('Content-Length','1024');
req.setHeader('Host','na1.salesforce.com ');
req.setHeader('Connection','keep-alive');
req.setHeader('soapAction', 'getObjects');
String url = 'https://na1.salesforce.com/services/Soap/c/10.0/session_key';
String str = '<?xml version="1.0" encoding="utf-8"?> '+
'<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:enterprise.soap.sforce.com\">'+
'<soapenv:Header>'+
'<urn:SessionHeader>'+
'<urn:sessionId>'+'session_ID'+'</urn:sessionId>'+
'</urn:SessionHeader>'+
'<urn:CallOptions><urn:client>CLIENT_ID</urn:client></urn:CallOptions>'+
'</soapenv:Header>'+
'<soapenv:Body>'+
'<describeGlobal></describeGlobal>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
req.setEndpoint(url);
req.setBody(str);
HTTPResponse resp = http.send(req);
system.debug('response:::'+xml_resp);
Session_ID : I got this value from UserInfo.getSessionID();
client_ID : I tried following values : UserInfo.getUserID();/Secret token
但我不能让它成为一个完美的呼吁来获得回应。
希望有人可以帮助...
为什么在 Apex 中使用出站 web 服务调用? Apex 可以使用Schema.getGlobalDescribe()
本机访问全局描述信息 - 这是访问描述结果的更好方法。
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_schema.htm有从 Apex 调用它的完整文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.