Transform SQL Queries to SOQL Queries in a Lightning App

June 20, 2020
public with sharing class Books4EveryoneHomeController {
  @AuraEnabled
  public static List<Book__c> getBooks(){
    return [SELECT ID, Name, Description__c
  FROM Book__c];
  
  }
    @AuraEnabled
public static List<Book__c> getBooksWithoutAuthors(){
  return [SELECT Name
    FROM Book__c
    WHERE Author__c = null];
}
    
@AuraEnabled
public static List<Book__c> getBooksAndAuthor(){
  return [SELECT Name, Description__c, Author__r.Name
    FROM Book__c];
}
    @AuraEnabled
public static List<Recommendation__c> getBookRecommendations(){
  return [SELECT Name, Review__c, Rating__c, Book__r.Name , Book__r.Author__r.Name
    FROM Recommendation__c
    WHERE Book__c != null];
}
      

}
<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="Books4EveryoneHomeController">
  <aura:attribute name="Books" type="Book__c" />
  <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
  <lightning:card title="Books4Everyone Books">
    <aura:set attribute="body">
      <table class="slds-table slds-table_bordered slds-table_cell-buffer">
        <thead>
          <tr class="slds-text-title_caps">
            <th scope="col">Book Titles</th>
            <th scope="col">Book Descriptions</th>
            <th scope="col">Author</th>
          </tr>
        </thead>
        <tbody>
          <aura:iteration items="{!v.Books}" var="books">
            <tr scope="row">
              <td> {!books.Name}</td>
              <td> {!books.Description__c}</td>
               <td> {!books.Author__r.Name}</td>
            </tr>
          </aura:iteration>
        </tbody>
      </table>
    </aura:set>
  </lightning:card>
</aura:component>
({
  doInit: function(component, event, helper) {
    var action = component.get("c.getBooksAndAuthor");
    action.setCallback(this, function(data) {
      component.set("v.Books", data.getReturnValue());
      console.log(data.getReturnValue());
    });
    $A.enqueueAction(action);
  }
})