You need to sign in to do that
Don't have an account?
Mohan 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:
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:
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) { ProductIdset.add(RecordQuoteItem.Product2Id); QuoteIdset.add(RecordQuoteItem.QuoteId); } } 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) { OpportunityIdset.add(quoteLineitemvalue.Quote.OpportunityId); } } 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>()); } OpportunityandOppolineitemMap.get(OpportunityLIRecord.OpportunityId).add(OpportunityLIRecord); } 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; OpportunityLineItemList.add(OpporVar); } } } } 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' ;