soql test class
 
Notifications
Clear all

soql test class

2 Posts
1 Users
0 Likes
1,014 Views
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

example for salesforce apex soql test class?

Issue Tags
1 Reply
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

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');
	}
}
Reply
Share: