You need to sign in to do that
Don't have an account?
sfdc@isha.ax1814
Urgent help ...help me on test class ?
Hi , Iam writing belowtest class . But Iam getting below error.
"System.QueryException: List has no rows for assignment to SObject ".
@isTest
private class SMXNPXSurveyBLTest {
static testMethod void testNPXsurveycasecreation(){
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
// Insert account as current user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
UserRole r = [SELECT Id FROM UserRole WHERE Name='COO'];
user u = new User(alias = 'jsmith', email='jsmith@acme.com',
emailencodingkey='UTF-8', lastname='Smith',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
timezonesidkey='America/Los_Angeles',
username='jsmith@acme.com');
System.RunAs(thisUser){
insert u;
Account a = new Account(Name='SMX Test Account', Industry='Test Industry',BillingPostalCode='211212',BillingStreet='TestStreet',BillingCity='TestCity',BillingCountry='Japan');
insert a;
Contact c = new Contact(FirstName='SMX TestFName1', LastName='SMX TestLName1', AccountID=a.id, Email='this.is.a.smx.test@acmedemo.com', Phone='9999999');
insert c;
Workgroup__c wg=New Workgroup__c();
wg.Name='test';
insert wg;
Workgroup_User_Role__c WUR = new Workgroup_User_Role__c();
WUR.Workgroup__c=wg.Id;
WUR.Case_type__c='Admin SR';
WUR.Product_Series__c='PULSE ONE';
WUR.Role_Name__c=r.id;
insert WUR;
case ca= new case();
ca.Accountid=a.id;
ca.contactid=c.id;
ca.subject='testsubject';
ca.Description='testdescription';
ca.status='submitted';
ca.Priority='High';
ca.Severity__c='test';
ca.origin='Email';
ca.Transaction_Type__c='Admin SR';
ca.Product_Series__c='PULSE ONE';
ca.Platform__c='PUSE ONE CONSOLE';
ca.Release__c ='2.0';
ca.Category__c='AAA';
ca.SR_Category1__c='Question';
ca.SR_Category2__c='Other';
Test.starttest();
insert ca;
Test.stoptest();
NPX_Survey_Record__c npx = new NPX_Survey_Record__c();
npx.Account__c=a.id;
npx.contact__c=c.id;
npx.case__c=ca.id;
npx.name='test';
npx.Primary_Score__c=10;
npx.primary_comment__c='test comment';
npx.Survey_ID__c='PULSESECURE_127771';
npx.Nomination_Process__c='Case Closure Nomination';
npx.Status__c='Nominated';
npx.Survey_Name__c='Technical Support Survey';
npx.Product_Series__c='CONNECT-SECURE';
npx.Survey_Details_URL__c='';
npx.Status_Description__c='test description';
Test.starttest();
insert npx;
test.stoptest();
npx.Primary_Score__c=6;
update npx;
}
}
}
Apex class:
public with sharing class SMXNPXSurveyBL
{
/*
* Method which takes a set of NPX Survey records and check for the primary score lessthan or equal to 6 and
*then create case if there is no case existed on the NPX Survey record.
*/
public static void createCase(List<NPX_Survey_Record__c> newRecords)
{
String severity;
String IsAlert = 'N';
Set<Id> nPXIds = new Set<Id>();
for(NPX_Survey_Record__c npx:newRecords){
nPXIds.add(npx.id);
}
List<case> caseList = new List<case>();
List<Case> ListCases = new List<Case>();
caseList=[select id,Casenumber,NPX_Survey_Record__c from Case where NPX_Survey_Record__c in :nPXIds];
if(!nPXIds.isEmpty()){
for(NPX_Survey_Record__c npx:newRecords){
if(npx.Primary_Score__c <= 6 && npx.Survey_ID__c =='PULSESECURE_127771'){
severity='High';
IsAlert = 'Y';
}
if(caseList.isEmpty() && (IsAlert == 'Y')){
Case c=new Case();
c.OwnerId=npx.OwnerID;
c.parentid=npx.case__c;
c.Subject='CPSE Negative Survey for '+npx.Account__r.Name;
c.Survey_Details__c ='Primary Score: '+ npx.Primary_Score__c+ '\n Primary Comment: '+npx.Primary_Comment__c;
//c.Status=status;
c.Priority=severity;
c.AccountId=npx.Account__c;
c.ContactId=npx.Contact__c;
c.Origin='Satmetrix';
//c.RecordTypeId=recType.Id;
c.NPX_Survey_Record__c=npx.id;
c.SurveyDetailsURL__c = npx.Survey_Details_URL__c;
ListCases.add(c);
}
}
insert ListCases;
}
}
}
Can you please help me out on this . how to pass this one
Regards,
Isha
"System.QueryException: List has no rows for assignment to SObject ".
@isTest
private class SMXNPXSurveyBLTest {
static testMethod void testNPXsurveycasecreation(){
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
// Insert account as current user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
UserRole r = [SELECT Id FROM UserRole WHERE Name='COO'];
user u = new User(alias = 'jsmith', email='jsmith@acme.com',
emailencodingkey='UTF-8', lastname='Smith',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
timezonesidkey='America/Los_Angeles',
username='jsmith@acme.com');
System.RunAs(thisUser){
insert u;
Account a = new Account(Name='SMX Test Account', Industry='Test Industry',BillingPostalCode='211212',BillingStreet='TestStreet',BillingCity='TestCity',BillingCountry='Japan');
insert a;
Contact c = new Contact(FirstName='SMX TestFName1', LastName='SMX TestLName1', AccountID=a.id, Email='this.is.a.smx.test@acmedemo.com', Phone='9999999');
insert c;
Workgroup__c wg=New Workgroup__c();
wg.Name='test';
insert wg;
Workgroup_User_Role__c WUR = new Workgroup_User_Role__c();
WUR.Workgroup__c=wg.Id;
WUR.Case_type__c='Admin SR';
WUR.Product_Series__c='PULSE ONE';
WUR.Role_Name__c=r.id;
insert WUR;
case ca= new case();
ca.Accountid=a.id;
ca.contactid=c.id;
ca.subject='testsubject';
ca.Description='testdescription';
ca.status='submitted';
ca.Priority='High';
ca.Severity__c='test';
ca.origin='Email';
ca.Transaction_Type__c='Admin SR';
ca.Product_Series__c='PULSE ONE';
ca.Platform__c='PUSE ONE CONSOLE';
ca.Release__c ='2.0';
ca.Category__c='AAA';
ca.SR_Category1__c='Question';
ca.SR_Category2__c='Other';
Test.starttest();
insert ca;
Test.stoptest();
NPX_Survey_Record__c npx = new NPX_Survey_Record__c();
npx.Account__c=a.id;
npx.contact__c=c.id;
npx.case__c=ca.id;
npx.name='test';
npx.Primary_Score__c=10;
npx.primary_comment__c='test comment';
npx.Survey_ID__c='PULSESECURE_127771';
npx.Nomination_Process__c='Case Closure Nomination';
npx.Status__c='Nominated';
npx.Survey_Name__c='Technical Support Survey';
npx.Product_Series__c='CONNECT-SECURE';
npx.Survey_Details_URL__c='';
npx.Status_Description__c='test description';
Test.starttest();
insert npx;
test.stoptest();
npx.Primary_Score__c=6;
update npx;
}
}
}
Apex class:
public with sharing class SMXNPXSurveyBL
{
/*
* Method which takes a set of NPX Survey records and check for the primary score lessthan or equal to 6 and
*then create case if there is no case existed on the NPX Survey record.
*/
public static void createCase(List<NPX_Survey_Record__c> newRecords)
{
String severity;
String IsAlert = 'N';
Set<Id> nPXIds = new Set<Id>();
for(NPX_Survey_Record__c npx:newRecords){
nPXIds.add(npx.id);
}
List<case> caseList = new List<case>();
List<Case> ListCases = new List<Case>();
caseList=[select id,Casenumber,NPX_Survey_Record__c from Case where NPX_Survey_Record__c in :nPXIds];
if(!nPXIds.isEmpty()){
for(NPX_Survey_Record__c npx:newRecords){
if(npx.Primary_Score__c <= 6 && npx.Survey_ID__c =='PULSESECURE_127771'){
severity='High';
IsAlert = 'Y';
}
if(caseList.isEmpty() && (IsAlert == 'Y')){
Case c=new Case();
c.OwnerId=npx.OwnerID;
c.parentid=npx.case__c;
c.Subject='CPSE Negative Survey for '+npx.Account__r.Name;
c.Survey_Details__c ='Primary Score: '+ npx.Primary_Score__c+ '\n Primary Comment: '+npx.Primary_Comment__c;
//c.Status=status;
c.Priority=severity;
c.AccountId=npx.Account__c;
c.ContactId=npx.Contact__c;
c.Origin='Satmetrix';
//c.RecordTypeId=recType.Id;
c.NPX_Survey_Record__c=npx.id;
c.SurveyDetailsURL__c = npx.Survey_Details_URL__c;
ListCases.add(c);
}
}
insert ListCases;
}
}
}
Can you please help me out on this . how to pass this one
Regards,
Isha
Can you let us know at which line it throws the error..?
--- > User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
// Insert account as current user
----> Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
----> UserRole r = [SELECT Id FROM UserRole WHERE Name='COO'];
Try the following test class it may be helpful for you: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Thanks for your response.
Hi Vamsi,
Yes iam getting error in that query only. can you please help me on the brief coding part.
I have already tried like that may be some where iam missing . Because here case creation is depends on te user role so user also need to be cretaed.
Help me on brief coding
So, add the following code of user's Dummy Data in test class as per your user's requirement:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi