Assignment 3

Create tabular structure to show data using jquery data table. you can use js remoting to fetch data from apex controller and then wrap that in jquery data table.
<!-- * @Name : JS_Assignment3.vfp * @Purpose : JavaScript Assignment 3. * @Description : To display the tabular structure to show list of Accounts, * and use js remoting to fetch data from apex controller and then wrap that in jquery data table . * @date : 15 09 2022 * @OtherRelateFiles : JS_Assignment3.vfp, JS_Assignment3_RemotingClass.apxc --> <apex:page sidebar="false" controller="JS_Assignment3_RemotingClass" showHeader="false" standardStylesheets="false"> <script type="text/javascript"> function getRecordsDetails() { var objName = document.getElementById("objectName").value; Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.JS_Assignment3_RemotingClass.getRecords}', objName, function(result, event){ if (event.status){ var l = result.length; if(l==0) { document.getElementById("details").innerHTML='<p>No Results!</p>'; } else{ var markup ='<table id="records">'; markup += '<tr><th>Name</th><th>Phone</th><th>Type</th><th>Annual Revenue</th></tr>'; for(var i=0; i<l;i++) { var recordDetail = '<tr>' + "<td>" +result[i].Name + "</td>" + "<td>" + result[i].Phone+ "</td>" + "<td>" + result[i].Type + "</td>" + "<td>" + result[i].AnnualRevenue + "</td>" + '</tr>'; markup += recordDetail; } document.getElementById("details").innerHTML = markup; } } else if (event.type === 'exception') { document.getElementById("details").innerHTML = event.message + "<br/>\n<pre>" + event.where + "</pre>"; } else{ document.getElementById("details").innerHTML = event.message; } }, {escape: true} ); } </script> <h2>JavaScript Remoting Demo</h2><br/> <div id="searchBar"> <input type="text" id="objectName" placeholder="Enter * to se all Accounts" /> <input type="button" value="Show All" id="btnSearch" onclick="getRecordsDetails();" /> </div> <div id="details"> </div> </apex:page>
/* * @Name : JS_Assignment3_RemotingClass.apxc * @Purpose : JavaScript Assignment 3. * @Description : To display the tabular structure to show list of Accounts, * and use js remoting to fetch data from apex controller and then wrap that in jquery data table . * @date : 15 09 2022 * @OtherRelateFiles : JS_Assignment3.vfp , JS_Assignment3_RemotingClass.apxc */ Public with sharing class JS_Assignment3_RemotingClass { public String objectName {get;set;} @RemoteAction Public static List <Account> getRecords(String objectName) { List <Account> sampleData = new List <Account>(); sampleData = Database.query('SELECT Id, Name,Phone,Type,AnnualRevenue FROM Account'); return sampleData; } }
/* * @Name : JS_Remoting_testClass.apxc * @Purpose : JavaScript Assignment 3. * @Description : To display the tabular structure to show list of Accounts, * and use js remoting to fetch data from apex controller and then wrap that in jquery data table . * @date : 15 09 2022 * @OtherRelateFiles : JSass03.vfp, JS_Assignment3_RemotingClass.apxc, JS_Remoting_testClass.apxc */ @isTest public class JS_Remoting_testClass { @testSetup static void MyAccountSetup() { List<Account> testAccount = new List<Account>(); for(Integer i=0;i<9;i++){ //Adding All Mandetory Fields and Required Fields testAccount.add(new Account(Name='TestAccount'+i)); } insert testAccount; } @isTest static void myFetchMethod(){ Test.startTest(); //Start Test Account AccountFetch = [SELECT Id, Name,Phone,Type,AnnualRevenue FROM Account WHERE Name='TestAccount0' LIMIT 1]; Test.stopTest(); //Stop Test JS_Assignment3_RemotingClass newClass= new JS_Assignment3_RemotingClass(); newClass.objectName =AccountFetch.Name; JS_Assignment3_RemotingClass.getRecords('TestAccount0'); // Verify System.assertEquals(AccountFetch.Name='TestAccount0', AccountFetch.Name); } }
Test Class Code Coverage 100%
Preview
Preview
After Inserting * to display all accounts
After Inserting * to display all accounts
Built with Potion.so