Hi All,
I tried test data to cover below condition but it's not working. Sharing the method and coverage and need some help for code coverage for lines in red.
////
List<Contact> lstContactsToUpdate = new List<Contact>();
List<OpportunityContactRole> lstOppContactRoles = new List<OpportunityContactRole>();
Map<Id, Opportunity> mapOppId2StageName = new Map<Id,Opportunity>();//This Map contains the opportunity Id and the opportunity record
Map<Id, String> mapOppId2ConPrimaryOpp = new Map<Id,String>();//This Map contains the opportunity Id and OCR's Contact Primary Opportunity
Map<Id, Id> mapOppId2OCRConId = new Map<Id,Id>();//This Map contains the opportunity Id and contact Id
Map<Id, OpportunityContactRole> mapOppId2OCRRec = new Map<Id,OpportunityContactRole>();//This Map contains the opportunity Id and the OCR record
Id customerRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Customer').getRecordTypeId();
Id prospectRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Prospect').getRecordTypeId();
Id salesRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Sales Opportunity').getRecordTypeId();
Opp_Forecast_Stage_Values__c ofs = Opp_Forecast_Stage_Values__c.getOrgDefaults();//added as a part of GTM-1522
try{
for(Id objOppId:newMapOppty.keySet()){
if(newMapOppty.get(objOppId).RecordTypeId == salesRecordTypeId && oldMapOppty.get(objOppId).StageName != newMapOppty.get(objOppId).StageName){
mapOppId2StageName.put(objOppId, newMapOppty.get(objOppId));
}
}
for(OpportunityContactRole objOCR : [SELECT Id,ContactId,Contact.Primary_Opportunity__c,Contact.Lead_Type__c,Contact.Contact_Status__c,Contact.UBE_Is_Converted__c,Contact.Last_SQL_Date__c,
Contact.Last_SQO_Date__c,OpportunityId,Opportunity.StageName FROM OpportunityContactRole WHERE OpportunityId IN: mapOppId2StageName.keyset()
AND (Contact.RecordTypeId =: customerRecordTypeId OR Contact.RecordTypeId =: prospectRecordTypeId)]){
If(objOCR.Contact.Primary_Opportunity__c != Null && objOCR.Contact.Primary_Opportunity__c != ''){
mapOppId2ConPrimaryOpp.put(objOCR.OpportunityId,objOCR.Contact.Primary_Opportunity__c);
}
mapOppId2OCRRec.put(objOCR.OpportunityId,objOCR);
mapOppId2OCRConId.put(objOCR.OpportunityId,objOCR.ContactId);
lstOppContactRoles.add(objOCR);
}
for(Id opid: mapOppId2StageName.KeySet()){
If(mapOppId2StageName.containsKey(mapOppId2ConPrimaryOpp.get(opid))){
String StageName = newMapOppty.get(opid).StageName;
Boolean CHECK = false;
OpportunityContactRole obj = mapOppId2OCRRec.get(opid);
Contact objContact = new Contact();
objContact.id = mapOppId2OCRConId.get(opid);
if(StageName == ofs.Stage_Closed_Won__c){
Hi, sorry for the inconvenience. If you don't receive a response here, we recommend reaching out to our support team for further assistance. You can do so by visiting https://help.salesforce.com/s/articleView?id=000393090&language=en_US&type=1