SOQL in a snippet

Here’s the super simple test page I used:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models/>
    <components>
        <buttonset uniqueid="sk-KX6-275">
            <buttons>
                <button type="custom" label="Do SOQL Query" uniqueid="sk-KX6-284" snippet="doSOQL"/>
            </buttons>
        </buttonset>
    </components>
    <resources>
        <labels/>
        <javascript>
            <jsitem location="inlinesnippet" cachelocation="false" name="doSOQL">var queryString = "SELECT Id, Name From Account LIMIT 10";
console.log("QUERY");
skuid.$.when(skuid.sfdc.api.query(queryString))
.done(function(queryResult) {
var records = queryResult.records;
console.log(records);
})
.fail(function(queryResult) {
console.error('Search failed: ' + queryResult.error);
}).always(function(queryResult) {
console.log('Original search request');
console.log(queryString);
});</jsitem>
        </javascript>
        <css/>
        <actionsequences/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>

Hi Louis,

Yes, to make it work in Salesforce Lightning Community, we have to do some adjustments:

1) Create a VisualforcePage and make sure the “Available for Lightning Experience, Lightning Communities, and the mobile app” - checkbox is checked and connect it to your Skuid Page with the right markup.

The markup looks something like this:

<apex:page readonly=“true” showheader=“false” sidebar=“false” doctype=“html-5.0” title=“soqlTest”> <skuid:page page=“soqlTest”/> </apex:page>

Hi Osman,

Thanks for that. Unfortunately I can’t use a visualforce page as this Skuid page is embedded in a custom Lightning Component and there is a lot of event communication between the skuid page and the lightning component. We also don’t want to use visualforce pages on this project.

I’ve solved my immediate issue with loading all the data on the page by building our own lightweight pagination solution. All the data (~5000 records) is pulled into the page and then the pagination just displays a page of those records at a time with previous/next controls (previously the pagination would first render all records and then following this would generate the pagination and re-render which was proving expensive in the browser). Out custom pagination seems to be working okay but it would be better if we could just dynamically query a range of records via SOQL. Are their plans to incorporate skuid.sfdc.api.query into Lightning? We might then be able to build a solution around it. For now we’ll stick with our current approach. Cheers!

Louis,

Would Salesforce’s Ajax Toolkit help?  You can pass in a dynamic SOQL and get an array of records back.

https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_more_samples.htm

You’ll need to load the data into your model, but you can do query more.

Thanks,

Bill

Hi Bill, that’s a fab idea - I’ve done some work with Salesforce’s rest api via jsforce but not from within a Skuid page. I wonder what the security implications would be running the Ajax login from a Skuid snippet as the site is on a public community… Thank you for your input! For now I’m just loading housings of records on the page and have built some lightweight pagination to cycle through the data. I’m hoping Skuid will release soql api queries from Lightning at a future date so I can tidy this up a little. Cheers!

skuid.sfdc.api.query() is a very powerful function to now be aware of. This will assist incredibly.

Thank you!!!