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
@isTest | |
public class AccountController_Test { | |
@isTest static void createAccount_test() { | |
test.startTest(); | |
AccountController controller = new AccountController(); | |
Account resultAcc = controller.createAccount('Test999', 20, 999); | |
system.assertEquals(resultAcc.Name, 'Test999'); | |
system.assertEquals(resultAcc.NumberOfEmployees, 20); | |
system.assertEquals(resultAcc.AnnualRevenue, 999); |
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
public class AccountController { | |
public Account createAccount(String accName, Integer employees, Decimal revenue) { | |
Account newAcc = new Account(Name = accName, NumberOfEmployees = employees, AnnualRevenue = revenue); | |
insert newAcc; | |
return newAcc; | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<apiVersion>47.0</apiVersion> | |
<isExposed>true</isExposed> | |
<targets> | |
<target>lightning__AppPage</target> | |
<target>lightning__RecordPage</target> | |
<target>lightning__HomePage</target> | |
</targets> | |
</LightningComponentBundle> |
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
import { LightningElement, track, api} from 'lwc'; | |
import { deleteRecord } from 'lightning/uiRecordApi'; | |
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; | |
const url = '/sfc/servlet.shepherd/document/download/'; | |
export default class LwcFilePreview extends LightningElement { | |
@track files = []; | |
@track isPreview; | |
@track currentRecId; |
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
<template> | |
<lightning-card> | |
<div class="slds-grid slds-wrap"> | |
<lightning-file-upload label="Upload Image" name="fileUpload" accept={acceptedFilesFormat} | |
record-id={recordId} multiple onuploadfinished={handleFileUpload}></lightning-file-upload> | |
<template if:false={isPreview}> | |
<template if:true={files}> | |
<div class="slds-col slds-size_12-of-12"> | |
<template if:true={files}> | |
<template for:each={files} for:item="fUrl"> |
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
import { LightningElement } from 'lwc'; | |
export default class lwcInput extends LightningElement { | |
handleChange(event) { | |
let inputCompValue = event.target.value; | |
let inputComp = this.template.querySelector('.inputComp'); | |
let splChars = /[0-9(@!#\$%\^\&*\)\(+=._-]/; | |
if(inputCompValue.match(splChars)) { | |
inputComp.setCustomValidity("Only character allowed."); | |
inputComp.reportValidity(); |
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
<template> | |
<lightning-input type="text" label="Comments" field-level-help="Only accepts characters" class="inputComp" | |
placeholder="Enter text" message-when-type-mismatch="only characters accepted" onchange={handleChange}></lightning-input> | |
</template> |
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
Set<Id> accId = new Set<Id>(); | |
for(Account acc : [SELECT Id, Name FROM Account LIMIT 100]) { | |
accId.add(acc.Id); | |
} | |
List<Id> strList = new List<Id>(accId); | |
system.debug('strList: ' + strList); | |
String str = string.join(strList, ','); | |
system.debug('String value : ' + str); |
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
Set<Id> accId = new Set<Id>(); | |
for(Account acc : [SELECT Id, Name FROM Account LIMIT 10]) { | |
accId.add(acc.Id); | |
} | |
system.debug(accId); | |
String str = ''+accId; | |
system.debug(str); |
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
public with sharing class SObjectHelper { | |
public static Object getRelatedFieldValue(sObject obj, String fieldName) { | |
if(fieldName.contains('.')){ | |
String relation = fieldName.substringBefore('.'); | |
String relatedField = fieldName.substringAfter('.'); | |
return SObjectHelper.getRelatedFieldValue((sObject)obj.getSObject(relation), relatedField); | |
} else { | |
return obj.get(fieldName); |
NewerOlder