-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3240ef9
commit 9fb0ebe
Showing
7 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
src-lookup-sample/main/default/classes/AccountContactLookup.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
public class AccountContactLookup implements LookupResult.ILookupResult { | ||
public final static Map<String, Object> ACCOUNT_ICON = new Map<String, Object>{ | ||
'iconName' => 'standard:contact' | ||
}; | ||
|
||
public List<LookupResult> getSelection( | ||
List<String> selectedIds, | ||
Map<String, Object> payload | ||
) { | ||
|
||
String accountId = (String) payload.get('accountId'); | ||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
if (accountId == null) { | ||
return result; | ||
} | ||
|
||
List<Contact> contacts = [ | ||
SELECT Name, Id, Phone | ||
FROM Contact | ||
WHERE AccountId = :accountId | ||
AND Id IN: selectedIds | ||
]; | ||
|
||
for (Contact contact : contacts) { | ||
result.add(buildResult(contact)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public List<LookupResult> getSearchResults( | ||
String searchTerm, | ||
List<String> selectedIds, | ||
Map<String, Object> payload | ||
) { | ||
|
||
String accountId = (String) payload.get('accountId'); | ||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
if (accountId == null) { | ||
return result; | ||
} | ||
|
||
searchTerm = '%' + searchTerm + '%'; | ||
|
||
List<Contact> contacts = [ | ||
SELECT Name, Email, Phone | ||
FROM Contact | ||
WHERE | ||
(Name LIKE :searchTerm | ||
OR Phone LIKE :searchTerm | ||
OR Email LIKE :searchTerm) | ||
AND AccountId = :accountId | ||
AND Id NOT IN :selectedIds | ||
]; | ||
|
||
for (Contact contact : contacts) { | ||
result.add(buildResult(contact)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public List<LookupResult> getDefaultSearchResults( | ||
Map<String, Object> payload | ||
) { | ||
|
||
String accountId = (String) payload.get('accountId'); | ||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
if (accountId == null) { | ||
return result; | ||
} | ||
|
||
List<Contact> contacts = [ | ||
SELECT Name, id, Phone | ||
FROM Contact | ||
WHERE AccountId = :accountId | ||
LIMIT 10 | ||
]; | ||
|
||
for (Contact contact : contacts) { | ||
result.add(buildResult(contact)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private LookupResult buildResult(Contact contact) { | ||
LookupResult result = new LookupResult(); | ||
result.id = contact.Id; | ||
result.icon = ACCOUNT_ICON; | ||
result.title = contact.Name; | ||
result.recordPayload = new Map<String, Object> { | ||
'name' => contact.Name, | ||
'phone' => contact.Phone | ||
}; | ||
|
||
return result; | ||
} | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
src-lookup-sample/main/default/classes/AccountContactLookup.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
public class AccountLookup implements LookupResult.ILookupResult { | ||
|
||
public final static Map<String, Object> ACCOUNT_ICON = new Map<String, Object>{ | ||
'iconName' => 'standard:account' | ||
}; | ||
|
||
public List<LookupResult> getSelection(List<String> selectedIds, Map<String, Object> payload) { | ||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
for (Account account : [SELECT Id, Name FROM Account WHERE Id IN: selectedIds]) { | ||
|
||
result.add(buildResult(account)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public List<LookupResult> getSearchResults( | ||
String searchTerm, | ||
List<String> selectedIds, | ||
Map<String, Object> payload) { | ||
|
||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
searchTerm = '%' + searchTerm + '%'; | ||
|
||
for (Account account : [ | ||
SELECT Id, Name | ||
FROM Account | ||
WHERE | ||
Name LIKE :searchTerm | ||
AND Id NOT IN :selectedIds | ||
]) { | ||
result.add(buildResult(account)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public List<LookupResult> getDefaultSearchResults(Map<String, Object> payload) { | ||
List<LookupResult> result = new List<LookupResult>(); | ||
|
||
for (Account account : [SELECT Id, Name FROM Account LIMIT 10]) { | ||
result.add(buildResult(account)); | ||
System.debug(account); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private LookupResult buildResult(Account account) { | ||
LookupResult result = new LookupResult(); | ||
result.id = account.Id; | ||
result.icon = ACCOUNT_ICON; | ||
result.title = account.Name; | ||
result.recordPayload = new Map<String, Object> { | ||
'type' => 'Contact', | ||
'name' => account.Name | ||
}; | ||
|
||
return result; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src-lookup-sample/main/default/classes/AccountLookup.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
36 changes: 36 additions & 0 deletions
36
src-lookup-sample/main/default/lwc/lookupAccount/lookupAccount.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<lightning-tabset variant="scoped"> | ||
<lightning-tab label='Working with payloads'> | ||
<lightning-card | ||
title="Working with payloads" | ||
> | ||
<div class="slds-form slds-form_stacked slds-var-m-around_xx-large"> | ||
<p class="slds-var-m-vertical_large"> | ||
<strong>Note:</strong> select an account to start | ||
</p> | ||
<c-lookup | ||
lwc:ref="lookup" | ||
unique-id="AccountLookup" | ||
label="Account Search" | ||
onchange={handleAccountChange} | ||
value={accountValue} | ||
required | ||
></c-lookup> | ||
<p>{accountText}</p> | ||
<c-lookup | ||
lwc:ref="lookup" | ||
unique-id="AccountContactLookup" | ||
label="Contact Search" | ||
value={contactValue} | ||
payload={contactPayload} | ||
disabled={accountValueEmpty} | ||
onchange={handleContactChange} | ||
required | ||
></c-lookup> | ||
<p>{contactText}</p> | ||
</div> | ||
</lightning-card> | ||
</lightning-tab> | ||
</lightning-tabset> | ||
</template> | ||
|
39 changes: 39 additions & 0 deletions
39
src-lookup-sample/main/default/lwc/lookupAccount/lookupAccount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { LightningElement, track } from "lwc"; | ||
import { NavigationMixin } from "lightning/navigation"; | ||
|
||
export default class LookupAccount extends NavigationMixin( LightningElement ) { | ||
|
||
@track contactPayload; | ||
accountValue; | ||
contactValue; | ||
accountText; | ||
contactText; | ||
|
||
|
||
handleAccountChange(event) { | ||
this.contactValue = []; | ||
this.accountText = ""; | ||
this.contactText = ""; | ||
this.accountValue = event.detail.value[0]; | ||
this.contactPayload = { accountId : event.detail.value[0] }; | ||
|
||
if (this.accountValue !== undefined) { | ||
const account = JSON.parse(JSON.stringify(event.detail.payload[0].recordPayload)); | ||
this.accountText = `Your account selected was ${account.name}`; | ||
} | ||
} | ||
|
||
handleContactChange(event) { | ||
this.contactText = ""; | ||
this.contactValue = event.detail.value[0]; | ||
|
||
if (this.accountValue === undefined || this.contactValue !== undefined) { | ||
const contact = JSON.parse(JSON.stringify(event.detail.payload[0].recordPayload)); | ||
this.contactText = `Your contact selected was ${contact.name} and its phone number is ${contact.phone}`; | ||
} | ||
} | ||
|
||
get accountValueEmpty() { | ||
return !this.accountValue; | ||
} | ||
} | ||
8 changes: 8 additions & 0 deletions
8
src-lookup-sample/main/default/lwc/lookupAccount/lookupAccount.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<isExposed>true</isExposed> | ||
<targets> | ||
<target>lightning__AppPage</target> | ||
</targets> | ||
</LightningComponentBundle> |