You need to sign in to do that
Don't have an account?

test class for cloned record
Hi,
Can someone help me with a test class for the below code?
It's a list view with a cloned functionality.
public with sharing class cloneCaseApplication {
@AuraEnabled
public static List < Case > cloneCaseApp() {
//Create variables
String currentuser = UserInfo.getUserId();
String emailAddress = UserInfo.getUserEmail();
Id userContactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
List < String > caseRecordtype = new List <String> ();
List < Case > casListCommunity = new List <case>();
List < Case > casListInternal = new List <case>();
system.debug('currentuser' + currentuser);
system.debug('userContactId' + userContactId);
// Add recordtype to list
caseRecordtype.add('Produksjonstilskudd');
caseRecordtype.add('Produksjonstilskudd_ny');
// Create list of all accounts which current user is linked to
List < Account > userAccounts = [SELECT Id,
name
FROM Account
WHERE Id IN(SELECT accountId FROM AccountContactRelation WHERE contactId =: userContactId)];
System.debug('userAccounts' + userAccounts);
// List all cases for accounts linked to user
if (userContactId != null) {
List < Case > cas = [SELECT Id,
Casenumber,
FROM Case
WHERE AccountId IN: userAccounts
AND RecordTypeId IN: caseRecordtype];
return cas;
}
else {
List < Case > casempt = [SELECT Id,
CaseNumber,
Account.Name
FROM Case
//WHERE RecordTypeId IN : caseRecordtype
LIMIT 20];
System.debug('casempt' + casempt);
return casempt;
}
}
@AuraEnabled
public static Boolean cloneRecord(String recId) {
system.debug('RecordToClone' + recid);
List < Case > toBeCloned = new List < Case > ();
Case cloneThis = [SELECT Id, CaseCloned__c FROM Case WHERE ID =: recId];
system.debug('clonethis' + cloneThis);
system.debug('this fires');
if (clonethis != null && Clonethis.CaseCloned__c != true) {
Case CloneTest = cloneThis.clone();
cloneThis.CaseCloned__c = true;
insert clonetest;
update clonethis;
system.debug('clontest' + clonetest);
return true;
} else if (Clonethis.CaseCloned__c == true) {}
return false;
}
}
Can someone help me with a test class for the below code?
It's a list view with a cloned functionality.
public with sharing class cloneCaseApplication {
@AuraEnabled
public static List < Case > cloneCaseApp() {
//Create variables
String currentuser = UserInfo.getUserId();
String emailAddress = UserInfo.getUserEmail();
Id userContactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
List < String > caseRecordtype = new List <String> ();
List < Case > casListCommunity = new List <case>();
List < Case > casListInternal = new List <case>();
system.debug('currentuser' + currentuser);
system.debug('userContactId' + userContactId);
// Add recordtype to list
caseRecordtype.add('Produksjonstilskudd');
caseRecordtype.add('Produksjonstilskudd_ny');
// Create list of all accounts which current user is linked to
List < Account > userAccounts = [SELECT Id,
name
FROM Account
WHERE Id IN(SELECT accountId FROM AccountContactRelation WHERE contactId =: userContactId)];
System.debug('userAccounts' + userAccounts);
// List all cases for accounts linked to user
if (userContactId != null) {
List < Case > cas = [SELECT Id,
Casenumber,
FROM Case
WHERE AccountId IN: userAccounts
AND RecordTypeId IN: caseRecordtype];
return cas;
}
else {
List < Case > casempt = [SELECT Id,
CaseNumber,
Account.Name
FROM Case
//WHERE RecordTypeId IN : caseRecordtype
LIMIT 20];
System.debug('casempt' + casempt);
return casempt;
}
}
@AuraEnabled
public static Boolean cloneRecord(String recId) {
system.debug('RecordToClone' + recid);
List < Case > toBeCloned = new List < Case > ();
Case cloneThis = [SELECT Id, CaseCloned__c FROM Case WHERE ID =: recId];
system.debug('clonethis' + cloneThis);
system.debug('this fires');
if (clonethis != null && Clonethis.CaseCloned__c != true) {
Case CloneTest = cloneThis.clone();
cloneThis.CaseCloned__c = true;
insert clonetest;
update clonethis;
system.debug('clontest' + clonetest);
return true;
} else if (Clonethis.CaseCloned__c == true) {}
return false;
}
}
Thanks, let us know if it helps you
All Answers
Thanks, let us know if it helps you
Thanks for the example. It does however has some flaws, but it's a good guide for the test I need.