setting RecordType in Test Coverage
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set. How am I setting the record type incorrectly in the test?
static testMethod void test6()
RecordType rt = [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name = 'Litigation'];
Account a = new Account(Name = 'test');
insert a;
Opportunity o = new Opportunity(AccountId = a.Id, CloseDate = Date.today(), Name = 'test', StageName = 'Identified');
insert o;
Case c = new Case(Opportunity__c = o.Id, Status = 'Open');
insert c;
advpm__Matter__c matter = new advpm__Matter__c(RecordTypeId = rt.Id, Case__c = c.Id,Date_of_Default__c = null, Outstanding_Balance__c = null, Rush__c= true, Concurrent_Deal__c=true);
Test.startTest();
MatterIntakeScreen controllerClass = new MatterIntakeScreen(new ApexPages.StandardController(c));
controllerClass.setRecordTypes('Litigation');
controllerClass.getRecordTypes();
controllerClass.saveMatter();
Test.stopTest();
system.assertEquals(controllerClass.getRecordTypes(), 'Litigation');
public class MatterIntakeScreen
public advpm__Matter__c matter get; set;
public String errorMessage get; set;
Case cs;
public MatterIntakeScreen(ApexPages.StandardController sc)
cs = (Case)sc.getRecord();
cs = [SELECT Id, Status, AccountId, Account.Name, Account.Legal_Status__c, Legal_Name__c,RecordType.Name,
Merchant_Number__c, Funded_Amount__c, Address__c, Fund_Date__c, Opportunity__c, Type, LP_Loan__c
FROM Case WHERE Id =: cs.Id];
errorMessage = null;
if(cs.Status == 'Closed')
errorMessage = 'Case is already Closed.';
cs.addError(errorMessage);
matter = new advpm__Matter__c();
private boolean formIsValid()
boolean isValid = true;
if (cs.Status == 'Closed')
cs.addError('Case is already Closed.');
isValid = false;
return isValid;
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
if(recordTypeList.size() > 0 )
return isValid;
public PageReference saveMatter()
Savepoint sp = Database.setSavepoint();
try
if (formIsValid() == false)
return null;
cs.Status = 'Closed';
update cs;
matter.advpm__Primary_Account__c = cs.AccountId;
if(cs.RecordType.Name.equals('Portfolio Management'))
matter.advpm__Matter_Number__c = cs.Merchant_Number__c;
matter.Loan_Amount__c = cs.Funded_Amount__c;
matter.Address_of_borrower__c = cs.Address__c;
matter.Date_of_Loan__c= cs.Fund_Date__c;
matter.Case__c = cs.Id;
matter.advpm__Opportunity__c = cs.Opportunity__c;
matter.LP_Loan__c = cs.LP_Loan__c;
if(recordTypes != null)
matter.RecordTypeId = recordTypes;
insert matter;
system.debug('newly inserted matter:: ' + matter);
....
catch (Exception ex)
System.debug('ex----'+ex);
ApexPages.addMessages(ex);
Database.rollback(sp);
return null;
String recordTypes;
public List<SelectOption> getItems()
List<SelectOption> options = new List<SelectOption>(6);
for(RecordType rt : [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name != 'Enforcement' AND Name != 'Standard'])
if(rt.Name == 'Litigation')
options.set(0, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Bankruptcy')
options.set(1, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Litigation - BK')
options.set(2, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Defense')
options.set(3, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Records Requests')
options.set(4, new SelectOption(rt.Id, rt.Name));
else
options.add(new SelectOption(rt.Id, rt.Name));
return options;
public String getRecordTypes()
return recordTypes;
public void setRecordTypes(String recordTypes)
this.recordTypes = recordTypes;
apex code-coverage record-type failing-tests getter
 |Â
show 2 more comments
up vote
1
down vote
favorite
I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set. How am I setting the record type incorrectly in the test?
static testMethod void test6()
RecordType rt = [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name = 'Litigation'];
Account a = new Account(Name = 'test');
insert a;
Opportunity o = new Opportunity(AccountId = a.Id, CloseDate = Date.today(), Name = 'test', StageName = 'Identified');
insert o;
Case c = new Case(Opportunity__c = o.Id, Status = 'Open');
insert c;
advpm__Matter__c matter = new advpm__Matter__c(RecordTypeId = rt.Id, Case__c = c.Id,Date_of_Default__c = null, Outstanding_Balance__c = null, Rush__c= true, Concurrent_Deal__c=true);
Test.startTest();
MatterIntakeScreen controllerClass = new MatterIntakeScreen(new ApexPages.StandardController(c));
controllerClass.setRecordTypes('Litigation');
controllerClass.getRecordTypes();
controllerClass.saveMatter();
Test.stopTest();
system.assertEquals(controllerClass.getRecordTypes(), 'Litigation');
public class MatterIntakeScreen
public advpm__Matter__c matter get; set;
public String errorMessage get; set;
Case cs;
public MatterIntakeScreen(ApexPages.StandardController sc)
cs = (Case)sc.getRecord();
cs = [SELECT Id, Status, AccountId, Account.Name, Account.Legal_Status__c, Legal_Name__c,RecordType.Name,
Merchant_Number__c, Funded_Amount__c, Address__c, Fund_Date__c, Opportunity__c, Type, LP_Loan__c
FROM Case WHERE Id =: cs.Id];
errorMessage = null;
if(cs.Status == 'Closed')
errorMessage = 'Case is already Closed.';
cs.addError(errorMessage);
matter = new advpm__Matter__c();
private boolean formIsValid()
boolean isValid = true;
if (cs.Status == 'Closed')
cs.addError('Case is already Closed.');
isValid = false;
return isValid;
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
if(recordTypeList.size() > 0 )
return isValid;
public PageReference saveMatter()
Savepoint sp = Database.setSavepoint();
try
if (formIsValid() == false)
return null;
cs.Status = 'Closed';
update cs;
matter.advpm__Primary_Account__c = cs.AccountId;
if(cs.RecordType.Name.equals('Portfolio Management'))
matter.advpm__Matter_Number__c = cs.Merchant_Number__c;
matter.Loan_Amount__c = cs.Funded_Amount__c;
matter.Address_of_borrower__c = cs.Address__c;
matter.Date_of_Loan__c= cs.Fund_Date__c;
matter.Case__c = cs.Id;
matter.advpm__Opportunity__c = cs.Opportunity__c;
matter.LP_Loan__c = cs.LP_Loan__c;
if(recordTypes != null)
matter.RecordTypeId = recordTypes;
insert matter;
system.debug('newly inserted matter:: ' + matter);
....
catch (Exception ex)
System.debug('ex----'+ex);
ApexPages.addMessages(ex);
Database.rollback(sp);
return null;
String recordTypes;
public List<SelectOption> getItems()
List<SelectOption> options = new List<SelectOption>(6);
for(RecordType rt : [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name != 'Enforcement' AND Name != 'Standard'])
if(rt.Name == 'Litigation')
options.set(0, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Bankruptcy')
options.set(1, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Litigation - BK')
options.set(2, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Defense')
options.set(3, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Records Requests')
options.set(4, new SelectOption(rt.Id, rt.Name));
else
options.add(new SelectOption(rt.Id, rt.Name));
return options;
public String getRecordTypes()
return recordTypes;
public void setRecordTypes(String recordTypes)
this.recordTypes = recordTypes;
apex code-coverage record-type failing-tests getter
2
Could you please include the relevant lines of code fromMatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.
â David Reed
9 hours ago
1
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago
 |Â
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set. How am I setting the record type incorrectly in the test?
static testMethod void test6()
RecordType rt = [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name = 'Litigation'];
Account a = new Account(Name = 'test');
insert a;
Opportunity o = new Opportunity(AccountId = a.Id, CloseDate = Date.today(), Name = 'test', StageName = 'Identified');
insert o;
Case c = new Case(Opportunity__c = o.Id, Status = 'Open');
insert c;
advpm__Matter__c matter = new advpm__Matter__c(RecordTypeId = rt.Id, Case__c = c.Id,Date_of_Default__c = null, Outstanding_Balance__c = null, Rush__c= true, Concurrent_Deal__c=true);
Test.startTest();
MatterIntakeScreen controllerClass = new MatterIntakeScreen(new ApexPages.StandardController(c));
controllerClass.setRecordTypes('Litigation');
controllerClass.getRecordTypes();
controllerClass.saveMatter();
Test.stopTest();
system.assertEquals(controllerClass.getRecordTypes(), 'Litigation');
public class MatterIntakeScreen
public advpm__Matter__c matter get; set;
public String errorMessage get; set;
Case cs;
public MatterIntakeScreen(ApexPages.StandardController sc)
cs = (Case)sc.getRecord();
cs = [SELECT Id, Status, AccountId, Account.Name, Account.Legal_Status__c, Legal_Name__c,RecordType.Name,
Merchant_Number__c, Funded_Amount__c, Address__c, Fund_Date__c, Opportunity__c, Type, LP_Loan__c
FROM Case WHERE Id =: cs.Id];
errorMessage = null;
if(cs.Status == 'Closed')
errorMessage = 'Case is already Closed.';
cs.addError(errorMessage);
matter = new advpm__Matter__c();
private boolean formIsValid()
boolean isValid = true;
if (cs.Status == 'Closed')
cs.addError('Case is already Closed.');
isValid = false;
return isValid;
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
if(recordTypeList.size() > 0 )
return isValid;
public PageReference saveMatter()
Savepoint sp = Database.setSavepoint();
try
if (formIsValid() == false)
return null;
cs.Status = 'Closed';
update cs;
matter.advpm__Primary_Account__c = cs.AccountId;
if(cs.RecordType.Name.equals('Portfolio Management'))
matter.advpm__Matter_Number__c = cs.Merchant_Number__c;
matter.Loan_Amount__c = cs.Funded_Amount__c;
matter.Address_of_borrower__c = cs.Address__c;
matter.Date_of_Loan__c= cs.Fund_Date__c;
matter.Case__c = cs.Id;
matter.advpm__Opportunity__c = cs.Opportunity__c;
matter.LP_Loan__c = cs.LP_Loan__c;
if(recordTypes != null)
matter.RecordTypeId = recordTypes;
insert matter;
system.debug('newly inserted matter:: ' + matter);
....
catch (Exception ex)
System.debug('ex----'+ex);
ApexPages.addMessages(ex);
Database.rollback(sp);
return null;
String recordTypes;
public List<SelectOption> getItems()
List<SelectOption> options = new List<SelectOption>(6);
for(RecordType rt : [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name != 'Enforcement' AND Name != 'Standard'])
if(rt.Name == 'Litigation')
options.set(0, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Bankruptcy')
options.set(1, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Litigation - BK')
options.set(2, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Defense')
options.set(3, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Records Requests')
options.set(4, new SelectOption(rt.Id, rt.Name));
else
options.add(new SelectOption(rt.Id, rt.Name));
return options;
public String getRecordTypes()
return recordTypes;
public void setRecordTypes(String recordTypes)
this.recordTypes = recordTypes;
apex code-coverage record-type failing-tests getter
I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set. How am I setting the record type incorrectly in the test?
static testMethod void test6()
RecordType rt = [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name = 'Litigation'];
Account a = new Account(Name = 'test');
insert a;
Opportunity o = new Opportunity(AccountId = a.Id, CloseDate = Date.today(), Name = 'test', StageName = 'Identified');
insert o;
Case c = new Case(Opportunity__c = o.Id, Status = 'Open');
insert c;
advpm__Matter__c matter = new advpm__Matter__c(RecordTypeId = rt.Id, Case__c = c.Id,Date_of_Default__c = null, Outstanding_Balance__c = null, Rush__c= true, Concurrent_Deal__c=true);
Test.startTest();
MatterIntakeScreen controllerClass = new MatterIntakeScreen(new ApexPages.StandardController(c));
controllerClass.setRecordTypes('Litigation');
controllerClass.getRecordTypes();
controllerClass.saveMatter();
Test.stopTest();
system.assertEquals(controllerClass.getRecordTypes(), 'Litigation');
public class MatterIntakeScreen
public advpm__Matter__c matter get; set;
public String errorMessage get; set;
Case cs;
public MatterIntakeScreen(ApexPages.StandardController sc)
cs = (Case)sc.getRecord();
cs = [SELECT Id, Status, AccountId, Account.Name, Account.Legal_Status__c, Legal_Name__c,RecordType.Name,
Merchant_Number__c, Funded_Amount__c, Address__c, Fund_Date__c, Opportunity__c, Type, LP_Loan__c
FROM Case WHERE Id =: cs.Id];
errorMessage = null;
if(cs.Status == 'Closed')
errorMessage = 'Case is already Closed.';
cs.addError(errorMessage);
matter = new advpm__Matter__c();
private boolean formIsValid()
boolean isValid = true;
if (cs.Status == 'Closed')
cs.addError('Case is already Closed.');
isValid = false;
return isValid;
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
if(recordTypeList.size() > 0 )
return isValid;
public PageReference saveMatter()
Savepoint sp = Database.setSavepoint();
try
if (formIsValid() == false)
return null;
cs.Status = 'Closed';
update cs;
matter.advpm__Primary_Account__c = cs.AccountId;
if(cs.RecordType.Name.equals('Portfolio Management'))
matter.advpm__Matter_Number__c = cs.Merchant_Number__c;
matter.Loan_Amount__c = cs.Funded_Amount__c;
matter.Address_of_borrower__c = cs.Address__c;
matter.Date_of_Loan__c= cs.Fund_Date__c;
matter.Case__c = cs.Id;
matter.advpm__Opportunity__c = cs.Opportunity__c;
matter.LP_Loan__c = cs.LP_Loan__c;
if(recordTypes != null)
matter.RecordTypeId = recordTypes;
insert matter;
system.debug('newly inserted matter:: ' + matter);
....
catch (Exception ex)
System.debug('ex----'+ex);
ApexPages.addMessages(ex);
Database.rollback(sp);
return null;
String recordTypes;
public List<SelectOption> getItems()
List<SelectOption> options = new List<SelectOption>(6);
for(RecordType rt : [Select Id, Name From RecordType Where SobjectType = 'advpm__Matter__c' AND Name != 'Enforcement' AND Name != 'Standard'])
if(rt.Name == 'Litigation')
options.set(0, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Bankruptcy')
options.set(1, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Litigation - BK')
options.set(2, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Defense')
options.set(3, new SelectOption(rt.Id, rt.Name));
else if(rt.Name == 'Records Requests')
options.set(4, new SelectOption(rt.Id, rt.Name));
else
options.add(new SelectOption(rt.Id, rt.Name));
return options;
public String getRecordTypes()
return recordTypes;
public void setRecordTypes(String recordTypes)
this.recordTypes = recordTypes;
apex code-coverage record-type failing-tests getter
apex code-coverage record-type failing-tests getter
edited 8 hours ago
asked 9 hours ago
Olivia
1,149318
1,149318
2
Could you please include the relevant lines of code fromMatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.
â David Reed
9 hours ago
1
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago
 |Â
show 2 more comments
2
Could you please include the relevant lines of code fromMatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.
â David Reed
9 hours ago
1
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago
2
2
Could you please include the relevant lines of code from
MatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.â David Reed
9 hours ago
Could you please include the relevant lines of code from
MatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.â David Reed
9 hours ago
1
1
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago
 |Â
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
As far as I can see, the issue seems to be on this line in your test class:
controllerClass.setRecordTypes('Litigation');
The query as I see in your MatterIntakeScreen#formIsValid()
, is as:
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
where you are fetching details based on the Record Type Id
.
If you have set the recordTypes
as a String value, the query above will never return any value and thus your execution will not get into the flow.
Either of the places needs a change, either you pass an appropriate record type id to the query, or (better approach) you change your query to accept a record type name/developer name.
very interesting. MyrecordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything moves
â Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actualId
value. But in your case it's just a string literal which will not have any match with anyId
and thus won't return any result.
â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand howrecordTypes
are being populated.
â Jayant Das
8 hours ago
add a comment |Â
up vote
2
down vote
Based on the highlighting, the query to the RecordType object (table) didn't return any rows.
Using an object describe to get the record type and it's ID is a better solution here and will probably also solve your issue.
The reason for this is that if there are no records of this type in the org yet, the RecordType object won't have any data in it. A describe of the object on the other hand, will always return its record types even if you haven't created any records of that type yet.
Assuming the developer name of the Record Type is Litigation
Schema.DescribeSObjectResult d = advpm__Matter__c.sObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> rtInfoMap = d.getRecordTypeInfosByDeveloperName();
Id rtId = rtInfoMap.get('Litigation').getRecordTypeId();
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
As far as I can see, the issue seems to be on this line in your test class:
controllerClass.setRecordTypes('Litigation');
The query as I see in your MatterIntakeScreen#formIsValid()
, is as:
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
where you are fetching details based on the Record Type Id
.
If you have set the recordTypes
as a String value, the query above will never return any value and thus your execution will not get into the flow.
Either of the places needs a change, either you pass an appropriate record type id to the query, or (better approach) you change your query to accept a record type name/developer name.
very interesting. MyrecordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything moves
â Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actualId
value. But in your case it's just a string literal which will not have any match with anyId
and thus won't return any result.
â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand howrecordTypes
are being populated.
â Jayant Das
8 hours ago
add a comment |Â
up vote
1
down vote
accepted
As far as I can see, the issue seems to be on this line in your test class:
controllerClass.setRecordTypes('Litigation');
The query as I see in your MatterIntakeScreen#formIsValid()
, is as:
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
where you are fetching details based on the Record Type Id
.
If you have set the recordTypes
as a String value, the query above will never return any value and thus your execution will not get into the flow.
Either of the places needs a change, either you pass an appropriate record type id to the query, or (better approach) you change your query to accept a record type name/developer name.
very interesting. MyrecordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything moves
â Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actualId
value. But in your case it's just a string literal which will not have any match with anyId
and thus won't return any result.
â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand howrecordTypes
are being populated.
â Jayant Das
8 hours ago
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
As far as I can see, the issue seems to be on this line in your test class:
controllerClass.setRecordTypes('Litigation');
The query as I see in your MatterIntakeScreen#formIsValid()
, is as:
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
where you are fetching details based on the Record Type Id
.
If you have set the recordTypes
as a String value, the query above will never return any value and thus your execution will not get into the flow.
Either of the places needs a change, either you pass an appropriate record type id to the query, or (better approach) you change your query to accept a record type name/developer name.
As far as I can see, the issue seems to be on this line in your test class:
controllerClass.setRecordTypes('Litigation');
The query as I see in your MatterIntakeScreen#formIsValid()
, is as:
List<RecordType> recordTypeList = [SELECT Id, Name FROM RecordType WHERE Id = :recordTypes];
where you are fetching details based on the Record Type Id
.
If you have set the recordTypes
as a String value, the query above will never return any value and thus your execution will not get into the flow.
Either of the places needs a change, either you pass an appropriate record type id to the query, or (better approach) you change your query to accept a record type name/developer name.
edited 4 hours ago
answered 8 hours ago
Jayant Das
7,5252320
7,5252320
very interesting. MyrecordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything moves
â Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actualId
value. But in your case it's just a string literal which will not have any match with anyId
and thus won't return any result.
â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand howrecordTypes
are being populated.
â Jayant Das
8 hours ago
add a comment |Â
very interesting. MyrecordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything moves
â Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actualId
value. But in your case it's just a string literal which will not have any match with anyId
and thus won't return any result.
â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand howrecordTypes
are being populated.
â Jayant Das
8 hours ago
very interesting. My
recordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything movesâ Olivia
8 hours ago
very interesting. My
recordTypes
variable is a string. It is working in practice so I thought ID's and String were interchangeable with binded values. I will play around with this and see if anything movesâ Olivia
8 hours ago
String and Ids are interchangeable, provided String consists of the actual
Id
value. But in your case it's just a string literal which will not have any match with any Id
and thus won't return any result.â Jayant Das
8 hours ago
String and Ids are interchangeable, provided String consists of the actual
Id
value. But in your case it's just a string literal which will not have any match with any Id
and thus won't return any result.â Jayant Das
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
thank you SO much! This was it, you are awesome!!
â Olivia
8 hours ago
Glad that it helped. It just needed few iterations to understand how
recordTypes
are being populated.â Jayant Das
8 hours ago
Glad that it helped. It just needed few iterations to understand how
recordTypes
are being populated.â Jayant Das
8 hours ago
add a comment |Â
up vote
2
down vote
Based on the highlighting, the query to the RecordType object (table) didn't return any rows.
Using an object describe to get the record type and it's ID is a better solution here and will probably also solve your issue.
The reason for this is that if there are no records of this type in the org yet, the RecordType object won't have any data in it. A describe of the object on the other hand, will always return its record types even if you haven't created any records of that type yet.
Assuming the developer name of the Record Type is Litigation
Schema.DescribeSObjectResult d = advpm__Matter__c.sObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> rtInfoMap = d.getRecordTypeInfosByDeveloperName();
Id rtId = rtInfoMap.get('Litigation').getRecordTypeId();
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
add a comment |Â
up vote
2
down vote
Based on the highlighting, the query to the RecordType object (table) didn't return any rows.
Using an object describe to get the record type and it's ID is a better solution here and will probably also solve your issue.
The reason for this is that if there are no records of this type in the org yet, the RecordType object won't have any data in it. A describe of the object on the other hand, will always return its record types even if you haven't created any records of that type yet.
Assuming the developer name of the Record Type is Litigation
Schema.DescribeSObjectResult d = advpm__Matter__c.sObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> rtInfoMap = d.getRecordTypeInfosByDeveloperName();
Id rtId = rtInfoMap.get('Litigation').getRecordTypeId();
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Based on the highlighting, the query to the RecordType object (table) didn't return any rows.
Using an object describe to get the record type and it's ID is a better solution here and will probably also solve your issue.
The reason for this is that if there are no records of this type in the org yet, the RecordType object won't have any data in it. A describe of the object on the other hand, will always return its record types even if you haven't created any records of that type yet.
Assuming the developer name of the Record Type is Litigation
Schema.DescribeSObjectResult d = advpm__Matter__c.sObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> rtInfoMap = d.getRecordTypeInfosByDeveloperName();
Id rtId = rtInfoMap.get('Litigation').getRecordTypeId();
Based on the highlighting, the query to the RecordType object (table) didn't return any rows.
Using an object describe to get the record type and it's ID is a better solution here and will probably also solve your issue.
The reason for this is that if there are no records of this type in the org yet, the RecordType object won't have any data in it. A describe of the object on the other hand, will always return its record types even if you haven't created any records of that type yet.
Assuming the developer name of the Record Type is Litigation
Schema.DescribeSObjectResult d = advpm__Matter__c.sObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> rtInfoMap = d.getRecordTypeInfosByDeveloperName();
Id rtId = rtInfoMap.get('Litigation').getRecordTypeId();
answered 9 hours ago
Mark Pond
17.9k13184
17.9k13184
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
add a comment |Â
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
thanks Mark. I have tried this with no success. I believe the issue it coming in because it is being called in the constructor (before the save happens) and the record type is not set before the save. I have the record types being set on a VFP and am pulling them to the controller with a getter and setter method. I will update the question with full details. I am unclear as to why the recordtypes variable is null but the other fields are not null.
â Olivia
8 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235372%2fsetting-recordtype-in-test-coverage%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Could you please include the relevant lines of code from
MatterIntakeScreen
that you're calling here as text, rather than an image? It's hard to follow the flow of control and not all of the important code is shown here.â David Reed
9 hours ago
1
Check the recordTypes variable used in formIsValid(). I suspect, based on the highlighting, that the query for the recordTypes returns an empty list
â Jochen
9 hours ago
In your class, where are the values for "recordTypes" and "matter" being set? In your test class, where is "matter" (about line 9) being used?
â Shane Steinfeld
9 hours ago
@Jochen you are right the query is returning an empty list which is why it can't get past. But the confusing thing is when I query for the list in dev console there are records. But it is just not picking up when I use the describe object or write the query in the test class.
â Olivia
8 hours ago
@DavidReed I updated the post with the MatterIntakeScreen class
â Olivia
8 hours ago