Examples for writing SOQL queries

edited July 4, 2017 in Questions
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?

Comments

  • edited December 18, 2014
    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.
  • edited March 2, 2017
    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


  • edited May 11, 2015
    How can i get data from model.With java script.
  • Rob HatchRob Hatch 🛠️ 
    edited September 1, 2016
  • edited May 11, 2015
    I have already check.Please check my code

    ------------------


         var params = arguments[0],
            step = params.step,
            stepEditor = step.editor,
          $ = skuid.$;
        stepEditor.clearMessages();
       
        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='';
       
        if(Firstname!==undefined)
        {
            Name+=Firstname;
        }
        if(Middlename!==undefined)
        {
            Name+=' '+Middlename;
        }
        if(LastName!==undefined)
        {
            Name+=' '+LastName;
        }
     
       
        if(Firstname===undefined  || LastName===undefined){
           
            alert('Please Enter First Name, Last Name');
            return false;
        }
       
    var Agcontact=skuid.model.getModel("Agcontact");
     Agcontact.doQuery=false;
     Agcontact.updateData();
    if(Firstname!==undefined){
    var FirstNamecondition = Agcontact.getConditionByName('FirstName');
    Agcontact.setCondition(FirstNamecondition,Firstname,true);
    }
    if(Middlename!==undefined){
    var Middlenamecondition = Agcontact.getConditionByName('MiddleName');
    Agcontact.setCondition(Middlenamecondition,Middlename,true);
    }
    if(LastName!==undefined){
    var LastNamecondition = Agcontact.getConditionByName('LastName');
    Agcontact.setCondition(LastNamecondition,LastName,true);
    }

    if(Birthdate!==undefined){
        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);
        if(age<18){
        alert("Candidate’s age is less than 18");   
        }
       
    var Birthdatecondition = Agcontact.getConditionByName('Birthdate');
    Agcontact.setCondition(Birthdatecondition,Birthdate,true);
    }
     Agcontact.recordsLimit=1;
     skuid.model.updateData([Agcontact]);
     
     
    //Agcontact.load();

     Agcontact.doQuery=true;
     Agcontact.updateData();
     //Agcontact.load();
    try{
       console.log('rohit');
       console.log(Agcontact);

      
      
      

     
     console.log(skuid.model.getModel("Agcontact").data);
     
     
    if(Agcontact.data.length>0)
    {
        var messages = [];
        var msg = [];
        msg.message=Name+' is already registor.Do you want to continue?...Click me';
        msg.severity='WARNING';
        messages.push(msg);
    if (messages.length) {
        var r = confirm(Name+' is already registor');
        if (r === true) {
            return true;
        } else {
           
              stepEditor.handleMessages(messages);
              return false;
        }
       
        }
               
    }

    }catch(e){
       
    }

     
     

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!