I'm new to Salesforce and Soap but I find myself needing to use both for this project. I need to use the Soap Salesforce API in Node, with the Partner WSDL. I'm also using the soap library for ease of use. I have setup a developer account in Salesforce that comes with test data already there. However, I am having a little trouble understanding what comes back in the API response vs what I see in my developer console. What I want to do is call describeGlobalAsync()
to see the objects available to query against. Then call describeSObjectsAsync
against a specific object to see fields etc. The console shows 51+items sorted by label
but the API response shows over 552 items.
Here are the steps I am following:
- Create a soap client
- Use that client to login via the Salesforce SOAP API
- Use the login response to set the serverUrl and sessionId for the client
- Make describeGlobalAsync call
- Log the response for investigation
I am also adding a header via addSoapHeader and I believe the type of call needs to have the namespace set, shown in Salesforce docs.
If I call describeGlobalAsync
without a parameter, I get the following error, so I'm passing in Account
for now:
No operation specified in request (the Body element has no child elements)
Here is my code so far:
const soap = require('soap');
const url = './partner.wsdl';
const util = require('util');
const namespaces = {
API: 'urn:partner.soap.sforce.com',
OBJECT: 'urn:sobject.partner.soap.sforce.com',
FAULT: 'urn:fault.partner.soap.sforce.com'
}
async function createClient(wsdl, namespace) {
let client = (await soap.createClientAsync(wsdl));
const loginResult = await client.loginAsync({username: username, password: password});
if (loginResult) {
client.setEndpoint(loginResult[0].result.serverUrl);
const sheader = {
SessionHeader : {
sessionId: loginResult[0].result.sessionId
}
};
client.addSoapHeader(sheader,"","tns", namespace);
return client;
} else {
throw new Error('cant login');
}
}
async function describeGlobal() {
try {
let client = await createClient(url, namespaces.OBJECT);
const headers = client.getSoapHeaders();
const globalObj = await client.describeGlobalAsync('Account');
console.log(JSON.stringify(globalObj[0].result.sobjects, null, 4));
let holder = [];
for (let elem of globalObj[0].result.sobjects) {
holder.push(elem.name)
}
console.log(holder)
} catch(err) {
console.log(err)
}
}
await describeGlobal();
Where I console.log(holder)
is where I get the following output:
[
'AIApplication',
'AIApplicationConfig',
'AIPredictionEvent',
'AcceptedEventRelation',
'Account',
'AccountChangeEvent',
'AccountCleanInfo',
'AccountContactRole',
'AccountContactRoleChangeEvent',
'AccountFeed',
'AccountHistory',
'AccountPartner',
'AccountShare',
'ActionLinkGroupTemplate',
'ActionLinkTemplate',
'ActiveFeatureLicenseMetric',
'ActivePermSetLicenseMetric',
'ActiveProfileMetric',
'ActivityHistory',
'AdditionalNumber',
'AggregateResult',
... 552 more items
]
It looks like this may be related objects but I have yet to be able to confirm that. Also, if I try await client.describeSObjectsAsync('Account');
I get LimitInfoHeader
, not any object info. What am I doing wrong?
- How can I get a list of all objects I can query against?
- How can I get key/field info about a particular object?