-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
28Questions
-
9Replies
Permissions should be checked before accessing resource {0}.
below heighleted code scan issue pls help me on this.
public static void continueCreateTicket(List<Case> caseList) {
if(Schema.sObjectType.Customer_Support_Internal_Request__c.isAccessible()) {
final List<Customer_Support_Internal_Request__c> newCsir;
newCsir = new List<Customer_Support_Internal_Request__c>();
Customer_Support_Internal_Request__c csir;
for(Case caseRec : caseList) {
csir = new Customer_Support_Internal_Request__c();
csir = doGetCSIR(caseRec,csirEarlyId);
if(csir != null) {
newCsir.add(csir);
}
}
if(!newCsir.isEmpty() && Customer_Support_Internal_Request__c.sObjectType.getDescribe().isAccessible()==true) {
insert newCsir;
}
}
Thanks!!
public static void continueCreateTicket(List<Case> caseList) {
if(Schema.sObjectType.Customer_Support_Internal_Request__c.isAccessible()) {
final List<Customer_Support_Internal_Request__c> newCsir;
newCsir = new List<Customer_Support_Internal_Request__c>();
Customer_Support_Internal_Request__c csir;
for(Case caseRec : caseList) {
csir = new Customer_Support_Internal_Request__c();
csir = doGetCSIR(caseRec,csirEarlyId);
if(csir != null) {
newCsir.add(csir);
}
}
if(!newCsir.isEmpty() && Customer_Support_Internal_Request__c.sObjectType.getDescribe().isAccessible()==true) {
insert newCsir;
}
}
Thanks!!
- Jai
- March 09, 2023
- Like
- 0
Cyclomatic Complexity and NPath complexity issues on my code
I am getting below code scan issues could you please suggest me to resolve or is there any best way to reduce the complexity.
The method 'createTicket1' has a Cyclomatic Complexity of 57.
The method createTicket1() has an NPath complexity of 832
below method
-----------------
Public static void createTicket1(List<case> caseList) {
system.debug('csirEarlyId '+csirEarlyId);
final List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
final Set<Id> accId = new Set<Id>();
final Set<Id> pid = new set<Id>();
final List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList) {
for(RecordType rt : listReTyp) {
if(cse.RecordTypeId == rt.Id) {
recFlag = true;
}
}
}
for(Case acCase : caseList) {
accId.add(acCase.AccountId);
}
for(Case pids : caseList) {
pid.add(pids.Patient__c);
}
final List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
final List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
final List<case> cListPid = [select id,Patient__c from Case where Patient__c != null and Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
for(case cs : caseList) {
if(pid != null && accId != null && recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth);
system.debug('cListQuarter '+cListQuarter);
system.debug('cListPid '+cListPid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined'&& (cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment'&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement' &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse'
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
}
}
insert newCsir;
}
Thanks!!
The method 'createTicket1' has a Cyclomatic Complexity of 57.
The method createTicket1() has an NPath complexity of 832
below method
-----------------
Public static void createTicket1(List<case> caseList) {
system.debug('csirEarlyId '+csirEarlyId);
final List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
final Set<Id> accId = new Set<Id>();
final Set<Id> pid = new set<Id>();
final List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList) {
for(RecordType rt : listReTyp) {
if(cse.RecordTypeId == rt.Id) {
recFlag = true;
}
}
}
for(Case acCase : caseList) {
accId.add(acCase.AccountId);
}
for(Case pids : caseList) {
pid.add(pids.Patient__c);
}
final List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
final List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
final List<case> cListPid = [select id,Patient__c from Case where Patient__c != null and Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
for(case cs : caseList) {
if(pid != null && accId != null && recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth);
system.debug('cListQuarter '+cListQuarter);
system.debug('cListPid '+cListPid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined'&& (cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment'&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement' &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse'
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
}
}
insert newCsir;
}
Thanks!!
- Jai
- March 03, 2023
- Like
- 0
could anyone please help me to get the code coverage for below class
apex class
------------------
public class EarlyAlertHandler {
public static Boolean createticketflag = false;
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Clinical Request').getRecordTypeId();
public static Id csirEarlyId = Schema.SObjectType.Customer_Support_Internal_Request__c.getRecordTypeInfosByName().get('Early Alert System (EAS)').getRecordTypeId();
Public static void createTicket1(List<case> caseList)
{
system.debug('case list '+caseList);
String getRecordTypeInfosByName ='Clinical_Request';
List<Case> newTicket = new List<Case>();
List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
Map<ID, RecordType> recordTypeMap1 = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Customer_Support_Internal_Request__c']);
Set<Id> accId = new Set<Id>();
Set<Id> pid = new set<Id>();
List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList)
{
for(RecordType rt : listReTyp)
{
if(cse.RecordTypeId == rt.Id)
{
recFlag = true;
}
}
}
system.debug('recFlag '+recFlag);
for(Case acCase : caseList)
{
accId.add(acCase.AccountId);
}
for(Case pids : caseList)
{
pid.add(pids.Patient__c);
}
Map<Id,Case> pidMap = new Map<Id,Case>(caseList);
List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
List<case> cListPid = [select id,Patient__c from Case where Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('Pids list '+cListPid.size());
system.debug('Pidslist '+cListPid);
system.debug('case list of month '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListQuarter1 '+cListQuarter);
//Map<String,ID> ticketrecoedtypes = new Map<string,Id>([select name,Id from RecordType where sObjectType = 'Case']);
for(case cs : caseList)
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true&& (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined')&&
(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario4');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario5');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario6');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse')
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2))
{
system.debug('Scenario 1');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
}
insert newCsir;
}
}
Test class
-----------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
Thanks!!
------------------
public class EarlyAlertHandler {
public static Boolean createticketflag = false;
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Clinical Request').getRecordTypeId();
public static Id csirEarlyId = Schema.SObjectType.Customer_Support_Internal_Request__c.getRecordTypeInfosByName().get('Early Alert System (EAS)').getRecordTypeId();
Public static void createTicket1(List<case> caseList)
{
system.debug('case list '+caseList);
String getRecordTypeInfosByName ='Clinical_Request';
List<Case> newTicket = new List<Case>();
List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
Map<ID, RecordType> recordTypeMap1 = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Customer_Support_Internal_Request__c']);
Set<Id> accId = new Set<Id>();
Set<Id> pid = new set<Id>();
List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList)
{
for(RecordType rt : listReTyp)
{
if(cse.RecordTypeId == rt.Id)
{
recFlag = true;
}
}
}
system.debug('recFlag '+recFlag);
for(Case acCase : caseList)
{
accId.add(acCase.AccountId);
}
for(Case pids : caseList)
{
pid.add(pids.Patient__c);
}
Map<Id,Case> pidMap = new Map<Id,Case>(caseList);
List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
List<case> cListPid = [select id,Patient__c from Case where Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('Pids list '+cListPid.size());
system.debug('Pidslist '+cListPid);
system.debug('case list of month '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListQuarter1 '+cListQuarter);
//Map<String,ID> ticketrecoedtypes = new Map<string,Id>([select name,Id from RecordType where sObjectType = 'Case']);
for(case cs : caseList)
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true&& (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined')&&
(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario4');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario5');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'
&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario6');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse')
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2))
{
system.debug('Scenario 1');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
}
insert newCsir;
}
}
Test class
-----------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
Thanks!!
- Jai
- February 27, 2023
- Like
- 0
Could you pls help me to write test class for the below code. I am not getting the coverage when i try with the below code
for(case cs : caseList)
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
insert newCsir;
Test class
------------------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
insert newCsir;
Test class
------------------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
- Jai
- February 24, 2023
- Like
- 0
is there any possibility to achieve this in Salesforce
Hello every one,
If the Asset status field equals "Inactive" and the "Inactive Reason" field equals "Missing/Lost Items", "Stolen Units" and "Trade-in" and a user tries to reactivate an Asset by changing the status field from "Inactive" to "Instaled,", the system must display a sort of "Alert Box" with 'Yes' and 'No' Button, with the message "Do you want to create a support ticket to request the approval for the Asset reactivation"
1).If the user clicks on "Yes", the system must create a support ticket and send an approval message to the manager in charge whenever an inactive Stolen Unit is reactivated.
2).If the user clicks on "No", there is no action, leaving the asset record with no changes.
Thanks!!
If the Asset status field equals "Inactive" and the "Inactive Reason" field equals "Missing/Lost Items", "Stolen Units" and "Trade-in" and a user tries to reactivate an Asset by changing the status field from "Inactive" to "Instaled,", the system must display a sort of "Alert Box" with 'Yes' and 'No' Button, with the message "Do you want to create a support ticket to request the approval for the Asset reactivation"
1).If the user clicks on "Yes", the system must create a support ticket and send an approval message to the manager in charge whenever an inactive Stolen Unit is reactivated.
2).If the user clicks on "No", there is no action, leaving the asset record with no changes.
Thanks!!
- Jai
- January 03, 2023
- Like
- 0
Could you please help me the way of solution for this scenario.
Hello,
If the Asset status field equals "Inactive" and the "Inactive Reason" field equals "Missing/Lost Items", "Stolen Units" and "Trade-in" and a user tries to reactivate an Asset by changing the status field from "Inactive" to "Instaled,", the system must display a sort of "Alert Box" with 'Yes' and 'No' Button, with the message "Do you want to create a support ticket to request the approval for the Asset reactivation"
1).If the user clicks on "Yes", the system must create a support ticket and send an approval message to the manager in charge whenever an inactive Stolen Unit is reactivated.
2).If the user clicks on "No", there is no action, leaving the asset record with no changes.
Thanks!!
If the Asset status field equals "Inactive" and the "Inactive Reason" field equals "Missing/Lost Items", "Stolen Units" and "Trade-in" and a user tries to reactivate an Asset by changing the status field from "Inactive" to "Instaled,", the system must display a sort of "Alert Box" with 'Yes' and 'No' Button, with the message "Do you want to create a support ticket to request the approval for the Asset reactivation"
1).If the user clicks on "Yes", the system must create a support ticket and send an approval message to the manager in charge whenever an inactive Stolen Unit is reactivated.
2).If the user clicks on "No", there is no action, leaving the asset record with no changes.
Thanks!!
- Jai
- December 23, 2022
- Like
- 0
Could you pls help me to write test class for the below code
Apex class
------------
public class NASurveyHandler {
Public static Boolean naSurveyCheck = false;
Public static void naServeycriteria(List<Case> caseList,map<id,Case> oldMap) {
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Pro_Survey__c != null || caseRecord.Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
naSurveyCheck = true;
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Pro_Survey__c != null && oldMap.get(caseRecord.Id).Pro_Survey__c != caseRecord.Pro_Survey__c) || (caseRecord.Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Pro_Survey_2__c != caseRecord.Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status) {
caseRecordID.add(caseRecord.Id);
caseSurveyMap.put(caseRecord.Id,caseRecord.Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Pro_Survey_2__c);
} else if(Trigger.isUpdate && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Customer Support') && caseRecord.Team_Function__c == 'NA Sales Support' && (caseRecord.Pro_Survey__c == 'Sales Support Team Survey'|| caseRecord.Pro_Survey_2__c == 'Sales Support Team Survey') && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status ) {
caseRecordID.add(caseRecord.Id);
caseSurveyMap.put(caseRecord.Id,caseRecord.Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
naServeyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void naServeyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
caseList = [select id,Pro_Survey__c,Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId,Team_Function__c from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
for(case caseRecord: caseList) {
if(caseRecord.Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Pro_Survey__c);
}
if(caseRecord.Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
insert lstSurveyInvitn;
}
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
public static List<SurveyInvitation> getConsumerCareSurveyInvitationLst(List<Case> caseList,Map<String,Id> mapProgramName,Boolean isAftrUpdate,Map<String, String> caseSurveyMap,Map<String, String> caseSurvey2Map) {
SurveyInvitation invitation;
List<SurveyInvitation> lstSurveyInvitn;
lstSurveyInvitn = new List<SurveyInvitation>();
for(Case caseRecord : caseList) {
if((isAftrUpdate && caseRecord.Pro_Survey__c != null) || (!caseSurveyMap.isEmpty() && caseSurveyMap.containsKey(caseRecord.Id) && caseRecord.Pro_Survey__c != null && caseSurveyMap.get(caseRecord.Id) != caseRecord.Pro_Survey__c)) {
invitation = new SurveyInvitation();
invitation.TFM_Cluster_Contact__c = caseRecord.TFM_Cluster_Contact__c;
invitation.Case__c = caseRecord.Id;
invitation.SurveyId = mapProgramName.get(caseRecord.Pro_Survey__c);
invitation.name = caseRecord.Pro_Survey__c;
lstSurveyInvitn.add(invitation);
}
if((isAftrUpdate && caseRecord.Pro_Survey_2__c != null) || (!caseSurvey2Map.isEmpty() && caseSurvey2Map.containsKey(caseRecord.Id) && caseRecord.Pro_Survey_2__c != null && caseSurvey2Map.get(caseRecord.Id) != caseRecord.Pro_Survey_2__c)) {
invitation = new SurveyInvitation();
invitation.TFM_Cluster_Contact__c = caseRecord.TFM_Cluster_Contact__c;
invitation.Case__c = caseRecord.Id;
invitation.SurveyId = mapProgramName.get(caseRecord.Pro_Survey_2__c);
invitation.name = caseRecord.Pro_Survey_2__c;
lstSurveyInvitn.add(invitation);
}
}
return lstSurveyInvitn;
}
}
Thanks!!
------------
public class NASurveyHandler {
Public static Boolean naSurveyCheck = false;
Public static void naServeycriteria(List<Case> caseList,map<id,Case> oldMap) {
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Pro_Survey__c != null || caseRecord.Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
naSurveyCheck = true;
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Pro_Survey__c != null && oldMap.get(caseRecord.Id).Pro_Survey__c != caseRecord.Pro_Survey__c) || (caseRecord.Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Pro_Survey_2__c != caseRecord.Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status) {
caseRecordID.add(caseRecord.Id);
caseSurveyMap.put(caseRecord.Id,caseRecord.Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Pro_Survey_2__c);
} else if(Trigger.isUpdate && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Customer Support') && caseRecord.Team_Function__c == 'NA Sales Support' && (caseRecord.Pro_Survey__c == 'Sales Support Team Survey'|| caseRecord.Pro_Survey_2__c == 'Sales Support Team Survey') && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status ) {
caseRecordID.add(caseRecord.Id);
caseSurveyMap.put(caseRecord.Id,caseRecord.Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
naServeyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void naServeyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
caseList = [select id,Pro_Survey__c,Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId,Team_Function__c from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
for(case caseRecord: caseList) {
if(caseRecord.Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Pro_Survey__c);
}
if(caseRecord.Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
insert lstSurveyInvitn;
}
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
public static List<SurveyInvitation> getConsumerCareSurveyInvitationLst(List<Case> caseList,Map<String,Id> mapProgramName,Boolean isAftrUpdate,Map<String, String> caseSurveyMap,Map<String, String> caseSurvey2Map) {
SurveyInvitation invitation;
List<SurveyInvitation> lstSurveyInvitn;
lstSurveyInvitn = new List<SurveyInvitation>();
for(Case caseRecord : caseList) {
if((isAftrUpdate && caseRecord.Pro_Survey__c != null) || (!caseSurveyMap.isEmpty() && caseSurveyMap.containsKey(caseRecord.Id) && caseRecord.Pro_Survey__c != null && caseSurveyMap.get(caseRecord.Id) != caseRecord.Pro_Survey__c)) {
invitation = new SurveyInvitation();
invitation.TFM_Cluster_Contact__c = caseRecord.TFM_Cluster_Contact__c;
invitation.Case__c = caseRecord.Id;
invitation.SurveyId = mapProgramName.get(caseRecord.Pro_Survey__c);
invitation.name = caseRecord.Pro_Survey__c;
lstSurveyInvitn.add(invitation);
}
if((isAftrUpdate && caseRecord.Pro_Survey_2__c != null) || (!caseSurvey2Map.isEmpty() && caseSurvey2Map.containsKey(caseRecord.Id) && caseRecord.Pro_Survey_2__c != null && caseSurvey2Map.get(caseRecord.Id) != caseRecord.Pro_Survey_2__c)) {
invitation = new SurveyInvitation();
invitation.TFM_Cluster_Contact__c = caseRecord.TFM_Cluster_Contact__c;
invitation.Case__c = caseRecord.Id;
invitation.SurveyId = mapProgramName.get(caseRecord.Pro_Survey_2__c);
invitation.name = caseRecord.Pro_Survey_2__c;
lstSurveyInvitn.add(invitation);
}
}
return lstSurveyInvitn;
}
}
Thanks!!
- Jai
- November 18, 2022
- Like
- 0
Please help me below future method code
Hi All,
In below code control is not entering into the future method (future method not getting executed) please help me on this
ublic static void consumerCareSurveyCriteria(List<Case> caseList,map<id,Case> oldMap){
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Invisalign_Pro_Survey__c != null || caseRecord.Invisalign_Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
system.debug('boolean test2 '+!oldMap.isEmpty());
system.debug('boolean test '+Trigger.isUpdate);
system.debug('record type11 '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
Boolean flag1 = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag1);
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c) || (caseRecord.Invisalign_Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey_2__c != caseRecord.Invisalign_Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status)
{
system.debug('boolean test '+Trigger.isUpdate);
system.debug('boolean test1 '+!oldMap.isEmpty());
system.debug('record type '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
system.debug('status '+caseRecord.Status);
Boolean flag = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag);
caseRecordID.add(caseRecord.Id);
system.debug('oldrectest '+oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c);
system.debug('surveyvalue '+caseRecord.Invisalign_Pro_Survey__c);
caseSurveyMap.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
system.debug('case Id '+caseRecordID);
createConsumerCareSurveyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void createConsumerCareSurveyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
system.debug('update test '+isAftrUpdate);
system.debug('caseSurveyMap11 '+caseSurveyMap);
system.debug('caseSurveyMap22 '+caseSurvey2Map);
system.debug('caseRecordID1111 '+caseIds);
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
system.debug('case ids11 '+caseIds);
caseList = [select id,Invisalign_Pro_Survey__c,Invisalign_Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
system.debug('case listrec '+caseList);
for(case caseRecord: caseList) {
if(caseRecord.Invisalign_Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey__c);
}
if(caseRecord.Invisalign_Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
system.debug('test invitation '+lstSurveyInvitn);
insert lstSurveyInvitn;
}
/*if (!trRecList.isEmpty() && Schema.sObjectType.Training_Records__c.isCreateable()) {
insert trRecList;
}*/
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
Thanks!!
In below code control is not entering into the future method (future method not getting executed) please help me on this
ublic static void consumerCareSurveyCriteria(List<Case> caseList,map<id,Case> oldMap){
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Invisalign_Pro_Survey__c != null || caseRecord.Invisalign_Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
system.debug('boolean test2 '+!oldMap.isEmpty());
system.debug('boolean test '+Trigger.isUpdate);
system.debug('record type11 '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
Boolean flag1 = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag1);
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c) || (caseRecord.Invisalign_Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey_2__c != caseRecord.Invisalign_Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status)
{
system.debug('boolean test '+Trigger.isUpdate);
system.debug('boolean test1 '+!oldMap.isEmpty());
system.debug('record type '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
system.debug('status '+caseRecord.Status);
Boolean flag = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag);
caseRecordID.add(caseRecord.Id);
system.debug('oldrectest '+oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c);
system.debug('surveyvalue '+caseRecord.Invisalign_Pro_Survey__c);
caseSurveyMap.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
system.debug('case Id '+caseRecordID);
createConsumerCareSurveyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void createConsumerCareSurveyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
system.debug('update test '+isAftrUpdate);
system.debug('caseSurveyMap11 '+caseSurveyMap);
system.debug('caseSurveyMap22 '+caseSurvey2Map);
system.debug('caseRecordID1111 '+caseIds);
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
system.debug('case ids11 '+caseIds);
caseList = [select id,Invisalign_Pro_Survey__c,Invisalign_Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
system.debug('case listrec '+caseList);
for(case caseRecord: caseList) {
if(caseRecord.Invisalign_Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey__c);
}
if(caseRecord.Invisalign_Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
system.debug('test invitation '+lstSurveyInvitn);
insert lstSurveyInvitn;
}
/*if (!trRecList.isEmpty() && Schema.sObjectType.Training_Records__c.isCreateable()) {
insert trRecList;
}*/
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
Thanks!!
- Jai
- November 01, 2022
- Like
- 0
Please help me on below code scan issue
The method ticketdetails() has an NPath complexity of 325
@AuraEnabled should have proper error handling
please help me to remidiate these code scan issues please
@auraEnabled
public static String ticketdetails (String id){
//System.debug('ticketdetails method calling'+id);
Case c = new Case ();
String s1 = String.valueof(Id);
Patient__c p1=new Patient__c();
Id conid;
if(Schema.sObjectType.Case.isAccessible() && s1.startsWith('500')){
c=[Select id,ContactId from Case where id=:id];
conid=c.ContactId;
}
if(Schema.sObjectType.Patient__c.isAccessible() && s1.startsWith('a02')){
p1=[Select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if (c.ContactId!=null || p1.Contact__c!=null || conid!=null){
return conid;
}
return null;
}
Thanks!!
@AuraEnabled should have proper error handling
please help me to remidiate these code scan issues please
@auraEnabled
public static String ticketdetails (String id){
//System.debug('ticketdetails method calling'+id);
Case c = new Case ();
String s1 = String.valueof(Id);
Patient__c p1=new Patient__c();
Id conid;
if(Schema.sObjectType.Case.isAccessible() && s1.startsWith('500')){
c=[Select id,ContactId from Case where id=:id];
conid=c.ContactId;
}
if(Schema.sObjectType.Patient__c.isAccessible() && s1.startsWith('a02')){
p1=[Select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if (c.ContactId!=null || p1.Contact__c!=null || conid!=null){
return conid;
}
return null;
}
Thanks!!
- Jai
- October 17, 2022
- Like
- 0
please help me on the below code scan issue
@AuraEnabled should have proper error handling
How to remidiate this code scan issue Please.
@auraEnabled
public static List<Case> getChartMap(String id){
//System.debug('getChartMap'+id);
case c1= new case();
String s1 = String.valueof(Id);
Id conid;
Patient__c p1=new Patient__c();
List<Case> cList= new List<Case>();
if(case.sObjectType.getDescribe().isAccessible() && s1.startsWith('500')){
c1=[select id,RecordType.Name,ContactId,Status from case where id=:id];
conid=c1.ContactId;//Added for SFSVC-145 Service Console UI Enhancements Patient
}
if(Patient__c.sObjectType.getDescribe().isAccessible() && s1.startsWith('a02')){
p1=[select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if(Opportunity.sObjectType.getDescribe().isAccessible() && s1.startsWith('006')){
opportunity opp1 = [select id,Contact__c from opportunity where id=:id];
conid = opp1.Contact__c;
}
if((c1.ContactId!=null || p1.Contact__c!=null || conid!=null) && case.sObjectType.getDescribe().isAccessible()){
cList=[select id,CaseNumber,BusinessHoursId,CreatedDate,RecordType.Name,ContactId,Status,Symptom_Code__c from case where ContactId=:conid and Status!='Closed' and Status!='Approved' and Status!='Rejected' order by createddate desc LIMIT 5];
}
return cList;
}
Thanks!!
How to remidiate this code scan issue Please.
@auraEnabled
public static List<Case> getChartMap(String id){
//System.debug('getChartMap'+id);
case c1= new case();
String s1 = String.valueof(Id);
Id conid;
Patient__c p1=new Patient__c();
List<Case> cList= new List<Case>();
if(case.sObjectType.getDescribe().isAccessible() && s1.startsWith('500')){
c1=[select id,RecordType.Name,ContactId,Status from case where id=:id];
conid=c1.ContactId;//Added for SFSVC-145 Service Console UI Enhancements Patient
}
if(Patient__c.sObjectType.getDescribe().isAccessible() && s1.startsWith('a02')){
p1=[select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if(Opportunity.sObjectType.getDescribe().isAccessible() && s1.startsWith('006')){
opportunity opp1 = [select id,Contact__c from opportunity where id=:id];
conid = opp1.Contact__c;
}
if((c1.ContactId!=null || p1.Contact__c!=null || conid!=null) && case.sObjectType.getDescribe().isAccessible()){
cList=[select id,CaseNumber,BusinessHoursId,CreatedDate,RecordType.Name,ContactId,Status,Symptom_Code__c from case where ContactId=:conid and Status!='Closed' and Status!='Approved' and Status!='Rejected' order by createddate desc LIMIT 5];
}
return cList;
}
Thanks!!
- Jai
- October 17, 2022
- Like
- 0
Please help me on below issue
The method 'getChartMap' has a Cyclomatic Complexity of 16.
Please help me to remidiate this code scan issue?
public static List<Case> getChartMap(String id){
//System.debug('getChartMap'+id);
case c1= new case();
String s1 = String.valueof(Id);
Id conid;
Patient__c p1=new Patient__c();
List<Case> cList= new List<Case>();
if(case.sObjectType.getDescribe().isAccessible() && s1.startsWith('500')){
c1=[select id,RecordType.Name,ContactId,Status from case where id=:id];
conid=c1.ContactId;//Added for SFSVC-145 Service Console UI Enhancements Patient
}
if(Patient__c.sObjectType.getDescribe().isAccessible() && s1.startsWith('a02')){
p1=[select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if(Opportunity.sObjectType.getDescribe().isAccessible() && s1.startsWith('006')){
opportunity opp1 = [select id,Contact__c from opportunity where id=:id];
conid = opp1.Contact__c;
}
if((c1.ContactId!=null || p1.Contact__c!=null || conid!=null) && case.sObjectType.getDescribe().isAccessible()){
cList=[select id,CaseNumber,BusinessHoursId,CreatedDate,RecordType.Name,ContactId,Status,Symptom_Code__c from case where ContactId=:conid and Status!='Closed' and Status!='Approved' and Status!='Rejected' order by createddate desc LIMIT 5];
}
return cList;
}
Thanks!!
Please help me to remidiate this code scan issue?
public static List<Case> getChartMap(String id){
//System.debug('getChartMap'+id);
case c1= new case();
String s1 = String.valueof(Id);
Id conid;
Patient__c p1=new Patient__c();
List<Case> cList= new List<Case>();
if(case.sObjectType.getDescribe().isAccessible() && s1.startsWith('500')){
c1=[select id,RecordType.Name,ContactId,Status from case where id=:id];
conid=c1.ContactId;//Added for SFSVC-145 Service Console UI Enhancements Patient
}
if(Patient__c.sObjectType.getDescribe().isAccessible() && s1.startsWith('a02')){
p1=[select id,Contact__c from Patient__c where id=:id];
conid=p1.Contact__c;
}
if(Contact.sObjectType.getDescribe().isAccessible() && s1.startsWith('003')){
conid=id;
}
if(Account.sObjectType.getDescribe().isAccessible() && s1.startsWith('001')){
Contact c2=[select id from Contact where accountid=:id order by createddate desc LIMIT 1];
conid=c2.id;
}
if(Opportunity.sObjectType.getDescribe().isAccessible() && s1.startsWith('006')){
opportunity opp1 = [select id,Contact__c from opportunity where id=:id];
conid = opp1.Contact__c;
}
if((c1.ContactId!=null || p1.Contact__c!=null || conid!=null) && case.sObjectType.getDescribe().isAccessible()){
cList=[select id,CaseNumber,BusinessHoursId,CreatedDate,RecordType.Name,ContactId,Status,Symptom_Code__c from case where ContactId=:conid and Status!='Closed' and Status!='Approved' and Status!='Rejected' order by createddate desc LIMIT 5];
}
return cList;
}
Thanks!!
- Jai
- October 17, 2022
- Like
- 0
need help on the below criteria
Hi All,
I need to schedule a flow on daily frequency. could you please help me on this
Thanks!!
I need to schedule a flow on daily frequency. could you please help me on this
Thanks!!
- Jai
- September 15, 2022
- Like
- 0
Please help me on the below error for test class
when i am running my test method i am geting the below error:
System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, This approval request requires the next approver to be determined by the Manager field. This value is empty. Please contact your administrator for more information.: []
Apex class:
-------------
Public static void IncentiveCompAutoSubmitApproval(List<Case> tickets)
{
try{
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
set<Id> ticketId = new set<Id>();
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
for(Case cs : tickets)
{ if(recordTypeMap.get(cs.recordTypeID).name.containsIgnoreCase('Incentive Compensation Request')&& cs.Status =='open'&& cs.managerid__c != null)
{
req1.setComments('Submitting request for approval.');
req1.setObjectId(cs.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
req1.setSkipEntryCriteria(true);
system.debug('test111 ' + cs.managerid__c);
Approval.ProcessResult result = Approval.process(req1);
system.debug('test222 ' + cs.managerid__c);
}
}
}catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
Test Method
------------------
@isTest static void IncentiveCompAutoSubmitApprovalTest()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId1;
cse.Status='Open';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
//cse.managerid__c = usr.ManagerId;
insert cse;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(cse.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
req1.setNextApproverIds(new Id[] {usr.ManagerId});
req1.setSkipEntryCriteria(true);
Approval.ProcessResult result1 = Approval.process(req1);
}
}
Thanks!!
System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, This approval request requires the next approver to be determined by the Manager field. This value is empty. Please contact your administrator for more information.: []
Apex class:
-------------
Public static void IncentiveCompAutoSubmitApproval(List<Case> tickets)
{
try{
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
set<Id> ticketId = new set<Id>();
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
for(Case cs : tickets)
{ if(recordTypeMap.get(cs.recordTypeID).name.containsIgnoreCase('Incentive Compensation Request')&& cs.Status =='open'&& cs.managerid__c != null)
{
req1.setComments('Submitting request for approval.');
req1.setObjectId(cs.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
req1.setSkipEntryCriteria(true);
system.debug('test111 ' + cs.managerid__c);
Approval.ProcessResult result = Approval.process(req1);
system.debug('test222 ' + cs.managerid__c);
}
}
}catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
Test Method
------------------
@isTest static void IncentiveCompAutoSubmitApprovalTest()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId1;
cse.Status='Open';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
//cse.managerid__c = usr.ManagerId;
insert cse;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(cse.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
req1.setNextApproverIds(new Id[] {usr.ManagerId});
req1.setSkipEntryCriteria(true);
Approval.ProcessResult result1 = Approval.process(req1);
}
}
Thanks!!
- Jai
- September 12, 2022
- Like
- 0
Please help me below code
I am getting below error when i run my test class
USER_DEBUG [49]|DEBUG|NullPointerException caught: Attempt to de-reference a null object
Apex class:
--------------
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname Limit 1];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
try{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('scanner@test.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}catch(NullPointerException np){
system.debug('NullPointerException caught: '+np.getMessage());
}
catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
test class
--------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'LATAM';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Order_Type__c='invisalign';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
insert caseList;
//EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'no-reply@test.com';
em.toaddress = 'scanner@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
//em.parentid = caseList[0].id;
EmailTemplate emailTemplateObj = new EmailTemplate();
emailTemplateObj.isActive = true;
emailTemplateObj.Name = 'iTero_back_office_Template';
emailTemplateObj.DeveloperName = 'iTero_back_office_Template';
emailTemplateObj.TemplateType = 'text';
emailTemplateObj.subject = 'test';
emailTemplateObj.Body = 'test123';
emailTemplateObj.FolderId = UserInfo.getUserId();
test.starttest();
insert emailTemplateObj;
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
USER_DEBUG [49]|DEBUG|NullPointerException caught: Attempt to de-reference a null object
Apex class:
--------------
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname Limit 1];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
try{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('scanner@test.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}catch(NullPointerException np){
system.debug('NullPointerException caught: '+np.getMessage());
}
catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
test class
--------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'LATAM';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Order_Type__c='invisalign';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
insert caseList;
//EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'no-reply@test.com';
em.toaddress = 'scanner@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
//em.parentid = caseList[0].id;
EmailTemplate emailTemplateObj = new EmailTemplate();
emailTemplateObj.isActive = true;
emailTemplateObj.Name = 'iTero_back_office_Template';
emailTemplateObj.DeveloperName = 'iTero_back_office_Template';
emailTemplateObj.TemplateType = 'text';
emailTemplateObj.subject = 'test';
emailTemplateObj.Body = 'test123';
emailTemplateObj.FolderId = UserInfo.getUserId();
test.starttest();
insert emailTemplateObj;
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
- Jai
- September 12, 2022
- Like
- 0
when i am running my test class i am getting following error please help me on that
System.NullPointerException: Attempt to de-reference a null object
Class.OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice: line 30, column 1
Class.OpportunityUpdateFromTicketHandlerTest.emailNotificationFromIteroBackOfficeTest: line 76, column 1
Apex class :
-----------------
ublic class OpportunityUpdateFromTicketHandler {
Public static void sendEmail(List<String> toAddress,EmailTemplate et)
{
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
Messaging.sendEmail(allmsg);
}
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('test@gmail.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}
Test Class
------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'NA';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'Test@test.com';
em.toaddress = 'test1@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
em.parentid = caseList[0].id;
test.starttest();
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
insert caseList;
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
Class.OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice: line 30, column 1
Class.OpportunityUpdateFromTicketHandlerTest.emailNotificationFromIteroBackOfficeTest: line 76, column 1
Apex class :
-----------------
ublic class OpportunityUpdateFromTicketHandler {
Public static void sendEmail(List<String> toAddress,EmailTemplate et)
{
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
Messaging.sendEmail(allmsg);
}
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('test@gmail.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}
Test Class
------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'NA';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'Test@test.com';
em.toaddress = 'test1@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
em.parentid = caseList[0].id;
test.starttest();
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
insert caseList;
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
- Jai
- September 08, 2022
- Like
- 0
Please help me below situation
I have a requirement to check if Case Owner ID is any Queue Id then change the Flag value to True.
I am strucked here how to compare Case Owner Id with List of Queue Id's.
Thanks!!
I am strucked here how to compare Case Owner Id with List of Queue Id's.
Thanks!!
- Jai
- September 05, 2022
- Like
- 0
REQUIRED_FIELD_MISSING, missing required field: [objectId]: [objectId]
code :
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
for(Case cs : tickets)
{
req1.setComments('Submitting request for approval.');
req1.setObjectId(cs.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
}
Approval.ProcessResult result = Approval.process(req1);
Thanks !!
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
for(Case cs : tickets)
{
req1.setComments('Submitting request for approval.');
req1.setObjectId(cs.Id);
req1.setSubmitterId(UserInfo.getUserId());
req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
}
Approval.ProcessResult result = Approval.process(req1);
Thanks !!
- Jai
- August 09, 2022
- Like
- 0
Please help me on the below error
trigger
----------
trigger OpportunityUpdateFromTicket on Case (before insert,after insert,before update,after update) {
if(trigger.isAfter&&(trigger.isInsert || trigger.isUpdate))
{
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(trigger.new,trigger.oldMap);
}
}
Helper class
------------------------
public class OpportunityUpdateFromTicketHandler {
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<String,Case> oldMapCase)
{
EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='iTero_back_office_Template'];
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
toAddress.add('scannerinstall@aligntech.com');
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
for(Case ticket :ticketList)
{
if(recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
}
}
}
Messaging.sendEmail(allmsg);
}
}
error:
----------
Method does not exist or incorrect signature: void emailNotificationFromIteroBackOffice(List<Case>, Map<Id,Case>) from the type OpportunityUpdateFromTicketHandler
Thanks!!
----------
trigger OpportunityUpdateFromTicket on Case (before insert,after insert,before update,after update) {
if(trigger.isAfter&&(trigger.isInsert || trigger.isUpdate))
{
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(trigger.new,trigger.oldMap);
}
}
Helper class
------------------------
public class OpportunityUpdateFromTicketHandler {
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<String,Case> oldMapCase)
{
EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='iTero_back_office_Template'];
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
toAddress.add('scannerinstall@aligntech.com');
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
for(Case ticket :ticketList)
{
if(recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
}
}
}
Messaging.sendEmail(allmsg);
}
}
error:
----------
Method does not exist or incorrect signature: void emailNotificationFromIteroBackOffice(List<Case>, Map<Id,Case>) from the type OpportunityUpdateFromTicketHandler
Thanks!!
- Jai
- July 13, 2022
- Like
- 0
please help me on the following scenario
Need to implent apex code when new email received to the case then case status should picklist update to 'New Email Received'
I written the following code but it is not working as expectd please corret me
public class UpdateCasestatusHandlere {
Public static void updateCasestatus(List<EmailMessage> newmailoncase)
{
Set<Id> caseIdSet = new Set<Id>();
List<Case> caseUpdate = new List<Case>();
List<Case> updatecase = new List<Case>();
for(EmailMessage em : newmailoncase)
{
if(em.Incoming && em.FromAddress == 'jtalapala@aligntech.com')
{
caseIdset.add(em.ParentId);
}
}
caseUpdate = [select id, Status,(select id, ParentId from EmailMessages) from Case where id In : caseIdset];
for(Case cse : caseUpdate)
{
cse.Status = 'New Email Received' ;
updatecase.add(cse);
}
if(!updatecase.isEmpty() && updatecase.size()>0)
{
update updatecase;
}
}
}
Thanks!!!
I written the following code but it is not working as expectd please corret me
public class UpdateCasestatusHandlere {
Public static void updateCasestatus(List<EmailMessage> newmailoncase)
{
Set<Id> caseIdSet = new Set<Id>();
List<Case> caseUpdate = new List<Case>();
List<Case> updatecase = new List<Case>();
for(EmailMessage em : newmailoncase)
{
if(em.Incoming && em.FromAddress == 'jtalapala@aligntech.com')
{
caseIdset.add(em.ParentId);
}
}
caseUpdate = [select id, Status,(select id, ParentId from EmailMessages) from Case where id In : caseIdset];
for(Case cse : caseUpdate)
{
cse.Status = 'New Email Received' ;
updatecase.add(cse);
}
if(!updatecase.isEmpty() && updatecase.size()>0)
{
update updatecase;
}
}
}
Thanks!!!
- Jai
- June 27, 2022
- Like
- 0
Help me on the following requirement please
I want to create 'Subscribe' button on a product page if any new product added to the list then we need to send notification to the users who are subscribed regarding new product information.
Please help me how can i approach with lightning aura components.
Thanks !!!
Please help me how can i approach with lightning aura components.
Thanks !!!
- Jai
- June 16, 2022
- Like
- 0
Cyclomatic Complexity and NPath complexity issues on my code
I am getting below code scan issues could you please suggest me to resolve or is there any best way to reduce the complexity.
The method 'createTicket1' has a Cyclomatic Complexity of 57.
The method createTicket1() has an NPath complexity of 832
below method
-----------------
Public static void createTicket1(List<case> caseList) {
system.debug('csirEarlyId '+csirEarlyId);
final List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
final Set<Id> accId = new Set<Id>();
final Set<Id> pid = new set<Id>();
final List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList) {
for(RecordType rt : listReTyp) {
if(cse.RecordTypeId == rt.Id) {
recFlag = true;
}
}
}
for(Case acCase : caseList) {
accId.add(acCase.AccountId);
}
for(Case pids : caseList) {
pid.add(pids.Patient__c);
}
final List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
final List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
final List<case> cListPid = [select id,Patient__c from Case where Patient__c != null and Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
for(case cs : caseList) {
if(pid != null && accId != null && recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth);
system.debug('cListQuarter '+cListQuarter);
system.debug('cListPid '+cListPid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined'&& (cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment'&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement' &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse'
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
}
}
insert newCsir;
}
Thanks!!
The method 'createTicket1' has a Cyclomatic Complexity of 57.
The method createTicket1() has an NPath complexity of 832
below method
-----------------
Public static void createTicket1(List<case> caseList) {
system.debug('csirEarlyId '+csirEarlyId);
final List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
final Set<Id> accId = new Set<Id>();
final Set<Id> pid = new set<Id>();
final List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
Boolean recFlag = false;
for(Case cse : caseList) {
for(RecordType rt : listReTyp) {
if(cse.RecordTypeId == rt.Id) {
recFlag = true;
}
}
}
for(Case acCase : caseList) {
accId.add(acCase.AccountId);
}
for(Case pids : caseList) {
pid.add(pids.Patient__c);
}
final List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
final List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
final List<case> cListPid = [select id,Patient__c from Case where Patient__c != null and Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
for(case cs : caseList) {
if(pid != null && accId != null && recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth.size());
system.debug('cListQuarter '+cListQuarter.size());
system.debug('cListPid '+cListPid.size());
system.debug('PIDTEST '+pid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
system.debug('cListMonth '+cListMonth);
system.debug('cListQuarter '+cListQuarter);
system.debug('cListPid '+cListPid);
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined'&& (cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Patient Records not properly examined';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment'&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Virtual Gingiva adjustment';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints'&& cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement' &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Treatment Complaints';
csir.Complaint_Sub_Type__c = 'Design Execution';
csir.Root_Cause__c = 'Features Placement';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
} else if(recFlag == true && cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid'
&& cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse'
&&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2)) {
final Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Non Valid';
csir.Complaint_type__c = 'Non Valid';
csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
csir.Root_Cause__c = 'Fit Issues due to Relapse';
csir.Trend_identified__c = '2 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
}
}
insert newCsir;
}
Thanks!!
- Jai
- March 03, 2023
- Like
- 0
Could you pls help me to write test class for the below code. I am not getting the coverage when i try with the below code
for(case cs : caseList)
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
insert newCsir;
Test class
------------------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
{
system.debug('1262 '+caseList);
createticketflag = true;
if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues'
&& cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
{
system.debug('Scenario2');
system.debug('csir rtype '+csirEarlyId);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome'
&& cs.Complaint_Sub_Type__c =='Aligner partially expressed movements'&&cs.Root_Cause__c =='Movements expressed in half')
&&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
{
system.debug('Scenario3');
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = cs.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Clinical Outcome';
csir.Complaint_Sub_Type__c = 'Aligner partially expressed movements';
csir.Root_Cause__c = 'Movements expressed in half';
csir.Trend_identified__c = '3 complaints per account in the same month';
csir.Account__c = cs.AccountId;
csir.Region__c = cs.Region__c;
csir.Patient__c = cs.Patient__c;
newCsir.add(csir);
system.debug('csir1 '+csir);
}
insert newCsir;
Test class
------------------------
public static testmethod void createTicket1test()
{
List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
insert lstTriggerControl;
List<Case> cList = new List<Case>();
List<Account> acList = new List<Account>();
TestDataBuilder testBuilder = new TestDataBuilder();
Account acc = new Account();
acc = testBuilder.dummyAccount(1);
acc.Business_Unit__c = 'NA';
acc.Payment_Terms__c = 'NT30';
acc.Billing_Language__c = 'English';
acc.Invoice_Preference__c = 'Email';
database.insert(acc);
acList.add(acc);
Account acc1 = new Account();
acc1 = testBuilder.dummyAccount(1);
acc1.Business_Unit__c = 'NA';
acc1.Payment_Terms__c = 'NT30';
acc1.Billing_Language__c = 'English';
acc1.Invoice_Preference__c = 'Email';
database.insert(acc1);
acList.add(acc1);
Account acc2 = new Account();
acc2 = testBuilder.dummyAccount(1);
acc2.Business_Unit__c = 'NA';
acc2.Payment_Terms__c = 'NT30';
acc2.Billing_Language__c = 'English';
acc2.Invoice_Preference__c = 'Email';
database.insert(acc2);
acList.add(acc2);
Contact con = new Contact();
con = testBuilder.dummyContact(1);
//database.insert(con);
List<Patient__c> pList = new List<Patient__c>();
Patient__c pid = new Patient__c();
pid.Name = 'test123';
pid.Account__c = acc.Id;
pid.Contact__c = con.Id;
Database.insert(pid);
pList.add(pid);
Patient__c pid1 = new Patient__c();
pid1.Name = 'test123';
pid1.Account__c = acc.Id;
pid1.Contact__c = con.Id;
pList.add(pid1);
Patient__c pid2 = new Patient__c();
pid2.Name = 'test123';
pid2.Account__c = acc.Id;
pid2.Contact__c = con.Id;
pList.add(pid2);
Case caseinsrt = new Case();
caseinsrt.Category__c = 'Product Deficiency';
caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
caseinsrt.Complaint_Sub_Type__c = 'Case Related';
caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
caseinsrt.Status ='closed';
caseinsrt.Date_Complaint_Reported__c=Date.Today();
caseinsrt.Sales_Order_Number__c='123456';
caseinsrt.accountid =acc.id;
caseinsrt.caller_role__c='Sales Team';
caseinsrt.consumer_advocacy_ticket__c = True;
caseinsrt.CAM_Process_Completed__c = True;
// caseinsrt.CAM_Opt_In__c = True;
caseinsrt.Credit_Request_Category__c = 'Replacement';
caseinsrt.RecordTypeId = eUiteroRecordTypeId;
caseinsrt.Doctor_First_Name__c = 'Test';
caseinsrt.Specific_Email__c ='test@test.com';
caseinsrt.ContactId = con.id;
cList.add(caseinsrt);
Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
csir.RecordTypeId = csirEarlyId;
csir.Ticket__c = caseinsrt.Id;
csir.Description__c = 'early alert system test';
csir.Status__c = 'In Progress';
csir.Ticket_Origin__c = 'Phone';
csir.Category__c = 'Product Deficiency';
csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
csir.Complaint_Sub_Type__c = 'Case Related';
csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
csir.Trend_identified__c = '4 complaints per account in the same month';
csir.Account__c = caseinsrt.AccountId;
csir.Region__c = caseinsrt.Region__c;
csir.Patient__c = caseinsrt.Patient__c;
Database.insert(csir);
- Jai
- February 24, 2023
- Like
- 0
Please help me below future method code
Hi All,
In below code control is not entering into the future method (future method not getting executed) please help me on this
ublic static void consumerCareSurveyCriteria(List<Case> caseList,map<id,Case> oldMap){
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Invisalign_Pro_Survey__c != null || caseRecord.Invisalign_Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
system.debug('boolean test2 '+!oldMap.isEmpty());
system.debug('boolean test '+Trigger.isUpdate);
system.debug('record type11 '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
Boolean flag1 = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag1);
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c) || (caseRecord.Invisalign_Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey_2__c != caseRecord.Invisalign_Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status)
{
system.debug('boolean test '+Trigger.isUpdate);
system.debug('boolean test1 '+!oldMap.isEmpty());
system.debug('record type '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
system.debug('status '+caseRecord.Status);
Boolean flag = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag);
caseRecordID.add(caseRecord.Id);
system.debug('oldrectest '+oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c);
system.debug('surveyvalue '+caseRecord.Invisalign_Pro_Survey__c);
caseSurveyMap.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
system.debug('case Id '+caseRecordID);
createConsumerCareSurveyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void createConsumerCareSurveyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
system.debug('update test '+isAftrUpdate);
system.debug('caseSurveyMap11 '+caseSurveyMap);
system.debug('caseSurveyMap22 '+caseSurvey2Map);
system.debug('caseRecordID1111 '+caseIds);
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
system.debug('case ids11 '+caseIds);
caseList = [select id,Invisalign_Pro_Survey__c,Invisalign_Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
system.debug('case listrec '+caseList);
for(case caseRecord: caseList) {
if(caseRecord.Invisalign_Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey__c);
}
if(caseRecord.Invisalign_Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
system.debug('test invitation '+lstSurveyInvitn);
insert lstSurveyInvitn;
}
/*if (!trRecList.isEmpty() && Schema.sObjectType.Training_Records__c.isCreateable()) {
insert trRecList;
}*/
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
Thanks!!
In below code control is not entering into the future method (future method not getting executed) please help me on this
ublic static void consumerCareSurveyCriteria(List<Case> caseList,map<id,Case> oldMap){
Set<Id> caseRecordID = new Set<Id>();
Map<String,String> caseSurveyMap = new Map<String,String>();
Map<String,String> caseSurvey2Map = new Map<String,String>();
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
for(Case caseRecord : caseList)
{
/*if(recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaints') && (caseRecord.Invisalign_Pro_Survey__c != null || caseRecord.Invisalign_Pro_Survey_2__c != null) && caseRecord.Patient_Email_Address__c !=null && caseRecord.Status == 'Closed')
{
if(Trigger.isInsert) {
caseRecordID.add(caseRecord.Id);
system.debug('case details11 '+caseRecordID);
}
}*/
system.debug('boolean test2 '+!oldMap.isEmpty());
system.debug('boolean test '+Trigger.isUpdate);
system.debug('record type11 '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
Boolean flag1 = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag1);
if(Trigger.isUpdate && !oldMap.isEmpty() && recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint') && (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c) || (caseRecord.Invisalign_Pro_Survey_2__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey_2__c != caseRecord.Invisalign_Pro_Survey_2__c) && caseRecord.Status == 'Closed' && caseRecord.Status!=oldMap.get(caseRecord.Id).Status)
{
system.debug('boolean test '+Trigger.isUpdate);
system.debug('boolean test1 '+!oldMap.isEmpty());
system.debug('record type '+recordTypeMap.get(caseRecord.recordTypeId).name.containsIgnoreCase('Consumer Complaint'));
system.debug('status '+caseRecord.Status);
Boolean flag = (caseRecord.Invisalign_Pro_Survey__c != null && oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c != caseRecord.Invisalign_Pro_Survey__c);
system.debug('Flag111 '+flag);
caseRecordID.add(caseRecord.Id);
system.debug('oldrectest '+oldMap.get(caseRecord.Id).Invisalign_Pro_Survey__c);
system.debug('surveyvalue '+caseRecord.Invisalign_Pro_Survey__c);
caseSurveyMap.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey__c);
caseSurvey2Map.put(caseRecord.Id,caseRecord.Invisalign_Pro_Survey_2__c);
}
}
if(!caseRecordID.isEmpty()) {
system.debug('case Id '+caseRecordID);
createConsumerCareSurveyInvitation(caseRecordID,caseSurveyMap,Trigger.isUpdate,caseSurvey2Map);
}
}
@future
public static void createConsumerCareSurveyInvitation(Set<Id> caseIds,Map<String,String> caseSurveyMap,Boolean isAftrUpdate,Map<String,String> caseSurvey2Map) {
try {
system.debug('update test '+isAftrUpdate);
system.debug('caseSurveyMap11 '+caseSurveyMap);
system.debug('caseSurveyMap22 '+caseSurvey2Map);
system.debug('caseRecordID1111 '+caseIds);
final Set<String> setProgramNames = new Set<String>();
List<Case> caseList;
caseList = new List<Case> ();
system.debug('case ids11 '+caseIds);
caseList = [select id,Invisalign_Pro_Survey__c,Invisalign_Pro_Survey_2__c,TFM_Cluster_Contact__c,ContactId from case where id in: caseIds WITH SECURITY_ENFORCED];
List<SurveyInvitation> lstSurveyInvitn ;
lstSurveyInvitn = new List<SurveyInvitation>();
system.debug('case listrec '+caseList);
for(case caseRecord: caseList) {
if(caseRecord.Invisalign_Pro_Survey__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey__c);
}
if(caseRecord.Invisalign_Pro_Survey_2__c != null) {
setProgramNames.add(caseRecord.Invisalign_Pro_Survey_2__c);
}
}
//Query Survey to get the ID's based on program names
final Map<String,Id> mapProgramName = new Map<String,Id>();
for(Survey surveyRecord : [select id,name from Survey where name in: setProgramNames WITH SECURITY_ENFORCED]) {
mapProgramName.put(surveyRecord.name,surveyRecord.id);
}
lstSurveyInvitn = getConsumerCareSurveyInvitationLst(caseList,mapProgramName,isAftrUpdate,caseSurveyMap,caseSurvey2Map);
//trRecList = getTrainingRecLst(caseList,mapProgramName,isAftrInsert,caseSurveyMap,caseSurvey2Map);
if (!lstSurveyInvitn.isEmpty() && Schema.sObjectType.SurveyInvitation.isCreateable()) {
system.debug('test invitation '+lstSurveyInvitn);
insert lstSurveyInvitn;
}
/*if (!trRecList.isEmpty() && Schema.sObjectType.Training_Records__c.isCreateable()) {
insert trRecList;
}*/
} catch(Exception e) {
final UCB_ExceptionService exceptionService = new UCB_ExceptionService(userinfo.getuserid(), 'NASurveyHandler Error', 'NASurveyHandler Error', '');
exceptionService.add(e);
exceptionService.publish();
}
}
Thanks!!
- Jai
- November 01, 2022
- Like
- 0
need help on the below criteria
Hi All,
I need to schedule a flow on daily frequency. could you please help me on this
Thanks!!
I need to schedule a flow on daily frequency. could you please help me on this
Thanks!!
- Jai
- September 15, 2022
- Like
- 0
Please help me below code
I am getting below error when i run my test class
USER_DEBUG [49]|DEBUG|NullPointerException caught: Attempt to de-reference a null object
Apex class:
--------------
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname Limit 1];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
try{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('scanner@test.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}catch(NullPointerException np){
system.debug('NullPointerException caught: '+np.getMessage());
}
catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
test class
--------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'LATAM';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Order_Type__c='invisalign';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
insert caseList;
//EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'no-reply@test.com';
em.toaddress = 'scanner@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
//em.parentid = caseList[0].id;
EmailTemplate emailTemplateObj = new EmailTemplate();
emailTemplateObj.isActive = true;
emailTemplateObj.Name = 'iTero_back_office_Template';
emailTemplateObj.DeveloperName = 'iTero_back_office_Template';
emailTemplateObj.TemplateType = 'text';
emailTemplateObj.subject = 'test';
emailTemplateObj.Body = 'test123';
emailTemplateObj.FolderId = UserInfo.getUserId();
test.starttest();
insert emailTemplateObj;
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
USER_DEBUG [49]|DEBUG|NullPointerException caught: Attempt to de-reference a null object
Apex class:
--------------
Public static EmailTemplate getQuery(String tempname)
{
EmailTemplate et = [select id,Subject,Body from EmailTemplate where DeveloperName =: tempname Limit 1];
return et;
}
// created by Jayaramu for Technical Det story
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<Id,Case> oldMapCase)
{
try{
EmailTemplate et = getQuery('iTero_back_office_Template');
system.debug('@@@@@@@@@'+et);
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
for(Case ticket :ticketList)
{
if(recordTypeMap!=null && ticket !=null && recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
toAddress.add('scanner@test.com');
system.debug('#######' + ticket.managerid__c);
if(toAddress !=null && et!=null)
{
sendEmail(toAddress, et);
}
}
}
}
}catch(NullPointerException np){
system.debug('NullPointerException caught: '+np.getMessage());
}
catch(QueryException qe){
system.debug('QueryException: '+qe);
}
catch(Exception e){
System.debug('Exception caught: ' + e.getMessage());
}
}
test class
--------------------
@isTest
public class OpportunityUpdateFromTicketHandlerTest {
public static Id eUiteroRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Contracts').getRecordTypeId();
public static Id eUiteroRecordTypeId1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Incentive Compensation Request').getRecordTypeId();
//public static Id eUiteroRecordTypeId2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('iTero Training').getRecordTypeId();
@isTest static void emailNotificationFromIteroBackOfficeTest(){
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com',
EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
TestDataBuilder testBuilder = new TestDataBuilder();
//insert manager
User usrManager = new User();
usrManager = testBuilder.dummyUser(0);
usrManager.UserRoleId = objr.Id;
insert usrManager;
//Insert User
User usr = new User();
usr = testBuilder.dummyUser(1);
usr.ManagerId = usrManager.Id;
usr.UserRoleId = objr.Id;
insert usr;
System.runAs(thisUser){
List<case> caseList = new List<case>();
//insert Case
Case cse = new Case();
cse.RecordTypeId = eUiteroRecordTypeId;
cse.Ticket_Type__c = 'New scanner sale';
cse.Origin = 'Web';
cse.Final_Status__c ='Processed/Assigned to Logistics';
cse.Region__c = 'NA';
//cse.Status='Approved';
cse.Type_of_Credit__c='Internal';
cse.Reason_for_Credit__c='Staff Discount Coupon';
cse.Order_Type__c='invisalign';
cse.Subject='Testing';
cse.Invoice_Number__c='1234567891';
cse.Amount_of_credit__c=10;
cse.Order_type__c='webstore';
cse.Sales_Order_Number__c='123456';
caseList.add(cse);
Case cse1 = new Case();
cse1.RecordTypeId = eUiteroRecordTypeId;
cse1.Ticket_Type__c = 'New scanner sale';
cse1.Origin = 'Web';
cse1.Final_Status__c ='Processed/Assigned to Logistics';
cse1.Region__c = 'LATAM';
//cse1.Status='Approved';
cse1.Type_of_Credit__c='Internal';
cse1.Reason_for_Credit__c='Staff Discount Coupon';
cse1.Order_Type__c='invisalign';
cse1.Subject='Testing';
cse1.Invoice_Number__c='1234567891';
cse1.Amount_of_credit__c=10;
cse1.Order_type__c='webstore';
cse1.Sales_Order_Number__c='123456';
caseList.add(cse1);
insert caseList;
//EmailTemplate et = OpportunityUpdateFromTicketHandler.getQuery('iTero_back_office_Template');
emailmessage em = new emailmessage();
em.fromaddress = 'no-reply@test.com';
em.toaddress = 'scanner@test.com';
em.subject = 'Test Email';
em.textbody = 'testing';
//em.parentid = caseList[0].id;
EmailTemplate emailTemplateObj = new EmailTemplate();
emailTemplateObj.isActive = true;
emailTemplateObj.Name = 'iTero_back_office_Template';
emailTemplateObj.DeveloperName = 'iTero_back_office_Template';
emailTemplateObj.TemplateType = 'text';
emailTemplateObj.subject = 'test';
emailTemplateObj.Body = 'test123';
emailTemplateObj.FolderId = UserInfo.getUserId();
test.starttest();
insert emailTemplateObj;
insert em;
Map<Id,Case> oldMapCase = new Map<Id,Case>();
oldMapCase.put(cse.Id, cse);
System.assertEquals(0, Limits.getEmailInvocations(), 'No emails should be sent');
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(caseList,oldMapCase);
System.assertEquals(1, Limits.getEmailInvocations(), 'Emails should be sent');
Test.stopTest();
}
}
}
Thanks!!
- Jai
- September 12, 2022
- Like
- 0
Please help me on the below error
trigger
----------
trigger OpportunityUpdateFromTicket on Case (before insert,after insert,before update,after update) {
if(trigger.isAfter&&(trigger.isInsert || trigger.isUpdate))
{
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(trigger.new,trigger.oldMap);
}
}
Helper class
------------------------
public class OpportunityUpdateFromTicketHandler {
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<String,Case> oldMapCase)
{
EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='iTero_back_office_Template'];
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
toAddress.add('scannerinstall@aligntech.com');
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
for(Case ticket :ticketList)
{
if(recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
}
}
}
Messaging.sendEmail(allmsg);
}
}
error:
----------
Method does not exist or incorrect signature: void emailNotificationFromIteroBackOffice(List<Case>, Map<Id,Case>) from the type OpportunityUpdateFromTicketHandler
Thanks!!
----------
trigger OpportunityUpdateFromTicket on Case (before insert,after insert,before update,after update) {
if(trigger.isAfter&&(trigger.isInsert || trigger.isUpdate))
{
OpportunityUpdateFromTicketHandler.emailNotificationFromIteroBackOffice(trigger.new,trigger.oldMap);
}
}
Helper class
------------------------
public class OpportunityUpdateFromTicketHandler {
Public static void emailNotificationFromIteroBackOffice(List<case> ticketList,Map<String,Case> oldMapCase)
{
EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='iTero_back_office_Template'];
Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
List<string> toAddress = new List<string>();
toAddress.add('scannerinstall@aligntech.com');
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
for(Case ticket :ticketList)
{
if(recordTypeMap.get(ticket.recordTypeID).name.containsIgnoreCase('iTero Contracts') && ticket.Ticket_Type__c =='New scanner sale' && ticket.Final_Status__c != oldMapCase.get(ticket.Id).Final_Status__c && ticket.Final_Status__c =='Processed/Assigned to Logistics' )
{
if(ticket.Region__c =='NA' || ticket.Region__c =='LATAM')
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(et.Id);
mail.setToAddresses(toAddress);
mail.setSubject(et.subject);
mail.setHTMLBody(et.Body);
allmsg.add(mail);
}
}
}
Messaging.sendEmail(allmsg);
}
}
error:
----------
Method does not exist or incorrect signature: void emailNotificationFromIteroBackOffice(List<Case>, Map<Id,Case>) from the type OpportunityUpdateFromTicketHandler
Thanks!!
- Jai
- July 13, 2022
- Like
- 0
Could you please help me on this. how to create validation rule for below requirement?
Please help me to restric any account manager (profile containing csx) to create an opportunity with type = new business.
- Jai
- March 29, 2021
- Like
- 0
Could you please suggest me on this. its not working as expected
Business_Unit__c ----- picklist
No_of_Employees__c ------ picklist
SPNG_Product__c ----- multi select picklist
when converting a Lead validation has to fire when Business_Unit__c value is Spanning the No_of_Employees__c and SPNG_Product__c are blank.
No_of_Employees__c and SPNG_Product__c these are mandatory fields.
AND(IsConverted, IF( ISPICKVAL( Business_Unit__c , 'Spanning') , AND( ISPICKVAL( No_of_Employees__c , '') , ISBLANK( SPNG_Product__c ) ) , false) )
No_of_Employees__c ------ picklist
SPNG_Product__c ----- multi select picklist
when converting a Lead validation has to fire when Business_Unit__c value is Spanning the No_of_Employees__c and SPNG_Product__c are blank.
No_of_Employees__c and SPNG_Product__c these are mandatory fields.
AND(IsConverted, IF( ISPICKVAL( Business_Unit__c , 'Spanning') , AND( ISPICKVAL( No_of_Employees__c , '') , ISBLANK( SPNG_Product__c ) ) , false) )
- Jai
- March 29, 2021
- Like
- 0