setting RecordType in Test Coverage

The name of the pictureThe name of the pictureThe name of the pictureClash 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');



enter image description here



enter image description here



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;












share|improve this question



















  • 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
















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');



enter image description here



enter image description here



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;












share|improve this question



















  • 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












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');



enter image description here



enter image description here



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;












share|improve this question















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');



enter image description here



enter image description here



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago

























asked 9 hours ago









Olivia

1,149318




1,149318







  • 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












  • 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







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










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.






share|improve this answer






















  • 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










  • 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

















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();





share|improve this answer




















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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










  • 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














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.






share|improve this answer






















  • 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










  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 4 hours ago

























answered 8 hours ago









Jayant Das

7,5252320




7,5252320











  • 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










  • 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
















  • 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










  • 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















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












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();





share|improve this answer




















  • 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














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();





share|improve this answer




















  • 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












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();





share|improve this answer












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();






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?