salesforce: use query method-chain syntax
Open
@mtuchi is already working on this.
Since Oct 7, 2024.
- Dominant language
- JavaScript
- Stars
- 24
- Forks
- 41
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 12
Description
jsforce exposes a method chain query syntax, like this:
conn.sobject("Contact")
.find(
// conditions in JSON object
{ LastName : { $like : 'A%' },
CreatedDate: { $gte : jsforce.Date.YESTERDAY },
'Account.Name' : 'Sony, Inc.' },
// fields in JSON object
{ Id: 1,
Name: 1,
CreatedDate: 1 }
)
.sort({ CreatedDate: -1, Name : 1 })
.limit(5)
.skip(10)
.execute(function(err, records) {
if (err) { return console.error(err); }
console.log("fetched : " + records.length);
});
Instead of relying on taking a query as a SOQL string, we should allow the find to be specified as a JSON object which defiens teh query criteria. We can also take options for sort, limit, skip etc.
Basically the idea would be instead of having to write this:
query(`SELECT Name, Email, (SELECT Campaign_Tag_Name__c FROM CampaignMembers
WHERE Campaign.RecordType.Name = 'Grupos, RTs ou Áreas Temáticas' and Campaign.IsActive = true)
FROM Contact
WHERE Id in (SELECT Contact__c FROM Deleted_Campaign_Member__c WHERE CreatedDate > ${state.lastSyncTime})
`)
Users can do something like tthis:
query({
from: 'Contact',
select: ['Name', 'Email', ''<nested query?>"] // maps to fields in find
where: {
CreatedDate: { $gte : state.lastSyncTime },
}
});
This is over-simplified because I don't know how the nested queries would work. But we should really be aspiring to building queries as JSON objects rather than SOQL strings
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.