function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohan Raj 33Mohan Raj 33 

How to write a test class for the update scenario?

Hi, I am an new bee for the test class so I have done my update scenario for my requirement for custom updated for the two custom fields as per named  same as SyncCheck__c in the OpportunityLineItem and QuoteLineItem for the way so can any one to know that to how to write a test class for the given code:
public class CustomSyncHandler {
    public static void UpdateTrigger (List<QuoteLineItem> InsertedQuote, Map<Id,QuoteLineItem> OldInsertedQuoteMap) {
        Set<Id> ProductIdset = new Set<Id>();
        Set<Id> QuoteIdset = new Set<Id>();
        Set<Id> OpportunityIdset = new Set<Id>();
        List<QuoteLineItem> QuoteLineItemList = new List<QuoteLineItem>();
        List<OpportunityLineItem> OpportunityLineItemList = new List<OpportunityLineItem>();

        for (QuoteLineItem RecordQuoteItem: InsertedQuote) {
           QuoteLineItem OldQuoteLineItemREC = OldInsertedQuoteMap.get(RecordQuoteItem.Id);
           if (OldQuoteLineItemREC.SyncCheck__c != RecordQuoteItem.SyncCheck__c) {
        If (QuoteIdset.size()>0) {
            QuoteLineItemList = [SELECT Id, QuoteId, Product2Id, SyncCheck__c, Quote.issyncing, Quote.OpportunityId FROM QuoteLineItem WHERE Product2Id IN :ProductIdset AND Quote.issyncing = True  ];
        If (QuoteLineItemList.size() > 0) {
            for (QuoteLineItem quoteLineitemvalue: QuoteLineItemList) {                  
        List<OpportunityLineItem> OpportunityLineitemvalueList = [SELECT Id, Name, OpportunityId, SyncCheck__c, Product2Id FROM OpportunityLineItem WHERE OpportunityId IN :OpportunityIdset AND Product2Id IN :ProductIdset];
        Map<Id, List<OpportunityLineItem>> OpportunityandOppolineitemMap = new Map<Id, List<OpportunityLineItem>>();
        for (OpportunityLineItem OpportunityLIRecord : OpportunityLineitemvalueList) {
            If (!OpportunityandOppolineitemMap.Containskey(OpportunityLIRecord.Id)) {
                OpportunityandOppolineitemMap.put(OpportunityLIRecord.OpportunityId, new List<OpportunityLineItem>());                
        system.debug('@@@ OpportunityandOppolineitemMap value is'+OpportunityandOppolineitemMap);
        for (QuoteLineItem QuoteLineItemRecord : QuoteLineItemList) { 
            if (OpportunityandOppolineitemMap.containsKey(QuoteLineItemRecord.Quote.OpportunityId)) {  
                 for (OpportunityLineItem OpporVar : OpportunityandOppolineitemMap.get(QuoteLineItemRecord.Quote.OpportunityId)) {

                     if (OpporVar.Product2Id == QuoteLineItemRecord.Product2Id) {
                         OpporVar.SyncCheck__c = QuoteLineItemRecord.SyncCheck__c;
        if (OpportunityLineItemList.size() > 0) {
            Update OpportunityLineItemList;  

Here I have the custom field for the sobjects of OpportunityLineItem AND QuoteLineItem as named SyncCheck__c it's to be in here I am providing the condititon to the quote to that appropriate(own) opportunity to they SYNC to that condition if I write some thing on the QuoteLineItem field as SyncCheck__c to be updatesd to the same Opportunities Line Item field in the Product of the same opportunity having the same name field SyncCheck__c is to be updated.

if you not understand clearly do following for check:
  • Provide the startsync to the condition to the quote to that related opportunity.
  • To create a  new QuoteLine Item to that Quote.
  • And write any word to the field in the quote Line Item to that field in named SyncCheck__c to some thing.((ex) In QuoteLine Item: SyncCheck__c = 'check';)
  • Then come to the Opportunity Line Item to the to preview it's should be updated to the opportunityLine item to field named SyncCheck__c then here the same word is updated.((ex) In OpportunityLineitem SyncCheck__c = 'check' ;
for any answers thanks in advance.