function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Selina SuarezSelina Suarez 

Error when tying to deploy a change set

Apex Test Failures

Class Name: MassConvertLead
Method Name: MassConvertLead testMassConvertLead System.QueryException:
Error Message: List has no rows for assignment to SObject
Stack Trace: Class.MassConvertLead.testMassConvertLead: line 55, column 1

I recently changed a record type name and line 55 is pointing to something referencing the record type name as follows: 
Id recordTypeId = [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'National Admissions Application'].Id;

I cannot get this to work at all. Can anyone offer any help? 

Thanks! 
Best Answer chosen by Selina Suarez
kaustav goswamikaustav goswami
Suppose you have chnaged the record type name from A to B.

Existing code was - [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'A']

Now you need to change this to [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'B']

This will fix the issue for the time being.

But please note that there ae other ways to make the independent of the changes made to name of the record type and that is by using another field called DeveloperName.

You query should be something like this - 

[Select Id From RecordType Where SObjectType = 'Lead' And DeveloperName = 'Appropriate Developer Name']

You can find the developer name from the record type page or by doing a simple query to the record type object.

Please let me know if you have further doubts.

Thanks,
Kaustav

All Answers

kaustav goswamikaustav goswami
In stead of using the Name field you should use the DeveloperName field in the SOQL query.

Use the scema explorer in eclipse to have a look at the field and its values.

Thanks,
Kaustav
Selina SuarezSelina Suarez
I didnt write the original code so I am not sure what the logic behind doing it this way was. What am I pulling from Eclipse?

kaustav goswamikaustav goswami
Suppose you have chnaged the record type name from A to B.

Existing code was - [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'A']

Now you need to change this to [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'B']

This will fix the issue for the time being.

But please note that there ae other ways to make the independent of the changes made to name of the record type and that is by using another field called DeveloperName.

You query should be something like this - 

[Select Id From RecordType Where SObjectType = 'Lead' And DeveloperName = 'Appropriate Developer Name']

You can find the developer name from the record type page or by doing a simple query to the record type object.

Please let me know if you have further doubts.

Thanks,
Kaustav
This was selected as the best answer
Selina SuarezSelina Suarez
So I changed it to the deloper name and I am getting the same error as follows: 
System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.MassConvertLead.testMassConvertLead: line 55, column 1

any thoughts?