我正在寻找 Salesforce 的 SOAP API 来获取所有 ApexJobs 的列表,
我使用了以下API进行登录。 请求类型:POST 请求网址:https://test.salesforce.com/services/Soap/u/ 正文(XML):
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<n1:login xmlns:n1="urn:partner.soap.sforce.com">
<n1:username>username</n1:username>
<n1:password>password+security token</n1:password>
</n1:login>
</env:Body>
</env:Envelope>
回应: MetaServiceUrl、SessionId、OrgId、UserId 等
现在,我应该使用哪个 API 来获取 ApexJobs 列表以及正文中应包含哪些内容?
谢谢你
从响应中读取会话 ID 和从现在开始使用的 url。
后续请求必须发送到您返回的内容(或者您可以将
mycompany--mysandbox.sandbox.my.salesforce.com
硬编码为端点,但随后您必须记住每次部署应用程序时更改它......从响应中读取它需要更多工作,但它有回报)
然后它就变成像任何其他表一样的普通查询? 如果您/您的管理员对在开发者控制台中运行此操作感到满意
SELECT ApexClass.Name, CreatedDate, CompletedDate, Status, ExtendedStatus
FROM AsyncApexJob
ORDER BY CreatedDate DESC
LIMIT 10
那么你需要的是
POST https://mycompany--mysandbox.sandbox.my.salesforce.com/services/Soap/u/59.0 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 649
Host: mycompany--mysandbox.sandbox.my.salesforce.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>00D... session id goes here. It'll start with 00D and have ! in it</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:query>
<urn:queryString>
SELECT ApexClass.Name, CreatedDate, CompletedDate, Status, ExtendedStatus
FROM AsyncApexJob
ORDER BY CreatedDate DESC
LIMIT 10
</urn:queryString>
</urn:query>
</soapenv:Body>
</soapenv:Envelope>
响应会有点像
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.partner.soap.sforce.com">
<soapenv:Header>
<LimitInfoHeader>
<limitInfo>
<current>12038</current>
<limit>19920000</limit>
<type>API REQUESTS</type>
</limitInfo>
</LimitInfoHeader>
</soapenv:Header>
<soapenv:Body>
<queryResponse>
<result xsi:type="QueryResult">
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:sObject">
<sf:type>AsyncApexJob</sf:type>
<sf:Id xsi:nil="true"/>
<sf:ApexClass xsi:type="sf:sObject">
<sf:type>ApexClass</sf:type>
<sf:Id xsi:nil="true"/>
<sf:Name>Redacted</sf:Name>
</sf:ApexClass>
<sf:CreatedDate>2023-12-14T21:10:34.000Z</sf:CreatedDate>
<sf:CompletedDate>2023-12-14T21:10:41.000Z</sf:CompletedDate>
<sf:Status>Completed</sf:Status>
<sf:ExtendedStatus xsi:nil="true"/>
</records>
<records xsi:type="sf:sObject">
<sf:type>AsyncApexJob</sf:type>
<sf:Id xsi:nil="true"/>
<sf:ApexClass xsi:type="sf:sObject">
<sf:type>ApexClass</sf:type>
<sf:Id xsi:nil="true"/>
<sf:Name>Redacted</sf:Name>
</sf:ApexClass>
<sf:CreatedDate>2023-12-14T21:10:17.000Z</sf:CreatedDate>
<sf:CompletedDate>2023-12-14T21:10:34.000Z</sf:CompletedDate>
<sf:Status>Completed</sf:Status>
<sf:ExtendedStatus xsi:nil="true"/>
</records>
(...)
<size>10</size>
</result>
</queryResponse>
</soapenv:Body>
</soapenv:Envelope>
实际上,您不会像那样手工制作它,您会“使用”WSDL 文件以在您选择的编程语言中使用。或者甚至有一些库用 C#、Java、PHP、Python 为您封装了大部分内容...但如果您想手工制作 - 像这样。