Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
choudharymanish8585 committed May 14, 2019
1 parent c0266b6 commit 0590688
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions AutoComplete/AutoCompleteController.cls
@@ -0,0 +1,16 @@
public with sharing class AutoCompleteController {
@AuraEnabled(cacheable=true)
public static List<SObject> getRecords(String searchString, String objectApiName, String idFieldApiName, String valueFieldApiName, String extendedWhereClause, Integer maxRecords){
searchString = String.escapeSingleQuotes(searchString);
objectApiName = String.escapeSingleQuotes(objectApiName);
idFieldApiName = String.escapeSingleQuotes(idFieldApiName);
valueFieldApiName = String.escapeSingleQuotes(valueFieldApiName);

if(extendedWhereClause == null){
extendedWhereClause = '';
}

String query = 'SELECT '+idFieldApiName+', '+valueFieldApiName+' FROM '+objectApiName+' WHERE '+valueFieldApiName+' LIKE \'%'+searchString+'%\' '+extendedWhereClause+' LIMIT '+maxRecords;
return Database.query(query);
}
}
5 changes: 5 additions & 0 deletions AutoComplete/AutoCompleteController.cls-meta.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="AutoCompleteController">
<apiVersion>45.0</apiVersion>
<status>Active</status>
</ApexClass>
16 changes: 16 additions & 0 deletions AutoComplete/AutoCompleteControllerTest.cls
@@ -0,0 +1,16 @@
@isTest
public with sharing class AutoCompleteControllerTest {
@TestSetup
static void makeData(){
Account acc = new Account(Name='Salesforce');
insert acc;
}

@isTest
public static void testGetRecords(){
List<SObject> accounts = AutoCompleteController.getRecords('sales', 'Account', 'Id', 'Name', null, 10);
System.assertEquals(1, accounts.size());
accounts = AutoCompleteController.getRecords('abc', 'Account', 'Id', 'Name', '', 100);
System.assertEquals(0, accounts.size());
}
}
5 changes: 5 additions & 0 deletions AutoComplete/AutoCompleteControllerTest.cls-meta.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="AutoCompleteControllerTest">
<apiVersion>45.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 0590688

Please sign in to comment.