开发者

Programatically fetch a list of all Salesforce Objects using apex in Salesforce

开发者 https://www.devze.com 2023-03-21 10:55 出处:网络
I want to fetch a list of all Salesforce objects. I found this link http://wiki.developerforce.com/index.php/Enterprise_Describe_Global

I want to fetch a list of all Salesforce objects. I found this link http://wiki.developerforce.com/index.php/Enterprise_Describe_Global

but there are some issues:

1) Missing session(Invalid session id) To prevent this i appended the session key in the url also for the post request but it shows no request.

Error : Internal Server Error (500)

2) I found somewhere and added clientId along with the session header but again no response.

Error : Internal Server Error (500)

code sample of web request:

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:::开发者_如何学Python'+xml_resp);

Session_ID : I got this value from UserInfo.getSessionID();

client_ID  : I tried following values : UserInfo.getUserID();/Secret token

but i couldnt make it a perfect call to get reaponse.

Hope somebody can help...


Why are you using an outbound web service call in Apex? Apex has native access to global describe information using Schema.getGlobalDescribe() - which is a much better way to access describe results.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_schema.htm has the full documentation for calling this from Apex.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号