Skip to content

Instantly share code, notes, and snippets.

@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);
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;
}
}
<?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>
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;
<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">
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();
<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>
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);
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);
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);