Notifications
Clear all
Jan 10, 2023 6:09 am
example for salesforce apex soql test class?
1 Reply
Jan 10, 2023 6:17 am
Here is one soql:
public with sharing class getRelatedQuotesDDSummaryLWC { @AuraEnabled(cacheable=true) public static List<SBQQ__Quote__c> retrieveQuoteData(string keySearch) { List<SBQQ__Quote__c> myQuoteList = [ SELECT Id, Name, SBQQ__Status__c, SBQQ__ExpirationDate__c, CTDDPEMP__c FROM SBQQ__Quote__c // WHERE SBQQ__Opportunity2__r.Name = :keySearch WHERE RecordType.Name <> 'POC' AND SBQQ__Opportunity2__r.Id = :keySearch ]; return myQuoteList; } }
Test class for it:
@isTest public class getRelatedQuotesDDSummaryLWC_Test { @isTest static void getRelatedQuotesDDSummaryLWCTestMethod() { //create a test opportunity Opportunity testOpp = new Opportunity(Name = 'TestOpp'); testOpp.StageName = 'TestStage'; testOpp.CloseDate = System.today(); insert testOpp; //create a test quote SBQQ__Quote__c testQuote = new SBQQ__Quote__c(); testQuote.SBQQ__Account__c = testOpp.AccountId; testQuote.SBQQ__Opportunity2__c = testOpp.Id; testQuote.SBQQ__Primary__c = true; insert testQuote; //test the method List<SBQQ__Quote__c> quoteList = getRelatedQuotesDDSummaryLWC.retrieveQuoteData(testOpp.Id); System.assert( quoteList != null); // System.assertEquals(1, quoteList.size(), 'quote retrieved'); } }