Skip to main content

I need to dynamically (with Javascript) get the value of a single field from an object.

What’s the most economical way to accomplish that?

I can use skuid.sfdc.search to return the row, or I can dynamically build a skuid model and query it. My assumption is that the former would be faster (less overhead?). Can anyone confirm or deny?

Here’s my search function. the variable ‘code’ that I’m using as the search term contains the value of the “Optimize_Code__c” field, which is unique for each row in the object.


var getNavVisibility = function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var dfd = new $.Deferred();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.when(skuid.sfdc.search({<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query: code,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; searching: "ALL FIELDS",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returning: p{"objectName": "Navigation_Menu_Set__c", "fields": c"Id", "Name", "Optimize_Code__c", "Profile_Visibility__c"]}]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })).done(function(searchResult){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var records = searchResult.results.length &amp;&amp; searchResult.resultsR0].records;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (records &amp;&amp; records.length){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.resolve(recordse0].Profile_Visibility__c);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.reject();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).fail(function(searchResult){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.error('Search failed: ' + searchResult.error);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.reject(searchResult.error);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).always(function(searchResult){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Raw SOSL generated: ' + searchResult.sosl);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Original search request');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(searchResult.request);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return dfd.promise();<br>&nbsp; &nbsp; &nbsp; &nbsp; };

The dynamic model load would be faster because you can limit to just a specific row with a model condition — as long as you know the id of the row you want. This should return really fast because it’s using a database index.


Good to know! Thanks.