Examples for writing SOQL queries

  • 3
  • Question
  • Updated 4 years ago
  • Answered
Are there any good examples that can be referred for writing SOQL query in skuid in-line snippet and then show the soql results in skuid table?
Photo of Vineet


  • 492 Points 250 badge 2x thumb

Posted 5 years ago

  • 3
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,686 Points 5k badge 2x thumb
I don't believe that you can write SOQL queries in an JavaScript snippet. Skuid uses models as soql. The syntax concept is, SELECT fields FROM models WHERE conditions. You can call apex methods from Javascript, but in my experience most soql scenarios can be handled with models.
Photo of Zach McElrath

Zach McElrath, Employee

  • 52,256 Points 50k badge 2x thumb
In general, the recommended approach is to create Models and Components in your Skuid page declaratively using the Page Composer, and then JavaScript can be used to interact with the Models and Components, e.g. re-query a Model, changing Models' Conditions, rerendering a Component, etc.

You don't have to load data into Models on initial page load, you can always set "Load Model data on page load" to false, and then query for / load the data later when you are ready using JavaScript, e.g.

var myModel = skuid.model.getModel('MyModel');
myModel.updateData(); // run the Model's query

This has many benefits, but one of the big ones is that you don't have to write a SOQL query --- you build your Model, and Skuid builds a SOQL query when it needs to using the current state of the Model --- so if you've activated / changed Conditions on your Model, Skuid will create a corresponding SOQL string to match the state of the Model. I think you'll find that you'll save yourself a lot of string manipulation hassle by not writing SOQL queries in JavaScript.

BUT, if you really need to create dynamic Models or Components client-side --- there are use cases for this, but they are very very rare --- here is a tutorial that will help you do this: Dynamic creation of Models and Components from JavaScript
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
How can i get data from model.With java script.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,678 Points 20k badge 2x thumb
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
I have already check.Please check my code


     var params = arguments[0],
        step = params.step,
        stepEditor = step.editor,
      $ = skuid.$;
    var contactModel=skuid.model.getModel("AddContact");
    var raw=contactModel.getFirstRow();
    var Firstname=raw.FirstName;
    var Middlename=raw.MiddleName;
    var LastName=raw.LastName;
    var Birthdate=raw.Birthdate;
    var Name='';
        Name+=' '+Middlename;
        Name+=' '+LastName;
    if(Firstname===undefined  || LastName===undefined){
        alert('Please Enter First Name, Last Name');
        return false;
var Agcontact=skuid.model.getModel("Agcontact");
var FirstNamecondition = Agcontact.getConditionByName('FirstName');
var Middlenamecondition = Agcontact.getConditionByName('MiddleName');
var LastNamecondition = Agcontact.getConditionByName('LastName');

    var bd=new Date(Birthdate); 
    var ageDifMs = Date.now() - bd.getTime();
    var ageDate = new Date(ageDifMs); // miliseconds from epoch
    var age=Math.abs(ageDate.getUTCFullYear() - 1970);
    alert("Candidate’s age is less than 18");   
var Birthdatecondition = Agcontact.getConditionByName('Birthdate');



    var messages = [];
    var msg = [];
    msg.message=Name+' is already registor.Do you want to continue?...Click me';
if (messages.length) {
    var r = confirm(Name+' is already registor');
    if (r === true) {
        return true;
    } else {
          return false;