You need to sign in to do that
Don't have an account?
Test Class List has no rows for assignement
My test class below keeps coming up with an error when i triy to move an updated trigger over to my production org via outbound change set or eclipse. The error is List has no rows for assignement. If anyone can help find the reason this test class keeps coming up with an error, i would appreciate it.

/**
* This class contains unit tests for validating the behavior of Apex classes
* and triggers.
*
* Unit tests are class methods that verify whether a particular piece
* of code is working properly. Unit test methods take no arguments,
* commit no data to the database, and are flagged with the testMethod
* keyword in the method definition.
*
* All test methods in an organization are executed whenever Apex code is deployed
* to a production organization to confirm correctness, ensure code
* coverage, and prevent regressions. All Apex classes are
* required to have at least 75% code coverage in order to be deployed
* to a production organization. In addition, all triggers must have some code coverage.
*
* The @isTest class annotation indicates this class only contains test
* methods. Classes defined with the @isTest annotation do not count against
* the organization size limit for all Apex scripts.
*
* See the Apex Language Reference for more information about Testing and Code Coverage.
*/
@isTest
private class Account_Create_Contact_TestClass {
static testMethod void myUnitTest() {
Profile p = [SELECT Id FROM Profile WHERE Name = 'BLX Telemarketer' LIMIT 1];
User u = [SELECT Id FROM User WHERE ProfileId = :p.Id AND User.IsActive = true LIMIT 1];
List<Account> accs = new List<Account>();
List<Account> conAccs = new List<Account>();
Set<Id> accIds = new Set<Id>();
Integer i = 0;
System.runAs(u) {
// Test Accounts with no Last Name has been added
for (Account a : [SELECT Id FROM Account LIMIT 50]) {
a.Eerstenaam__c = 'Test First Name';
}
if (!accs.isEmpty()) {
update(accs);
accs.clear();
}
for (Account a : [SELECT Id FROM Account LIMIT 50]) {
accIds.add(a.Id);
a.Eerstenaam__c = 'Test First Name';
a.Achternaam__c = 'Test Last Name';
a.Nieuwsbrieven_ontvangen__c = false;
if (i == 0) {
a.Nieuwsbrieven_Ontvangen__c = true;
a.Dezelfde_Email__c = true;
i = 1;
}
else if (i == 1) {
i = 2;
a.Status_Belactie_2010__c = 'Wil Gebeld Worden Door Account Manager';
a.Opmerkingen__c = 'This is a test Task';
}
else {
a.Achternaam__c = NULL;
}
accs.add(a);
}
if (!accs.isEmpty()) {
update(accs);
}
for (Contact c : [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId IN :accIds AND LastName = 'Test Last Name']) {
Account a = new Account(Id=c.AccountId);
a.Achternaam__c = c.LastName;
conAccs.add(a);
}
if (!conAccs.isEmpty()) {
update(conAccs);
}
}
}
}
/**
* This class contains unit tests for validating the behavior of Apex classes
* and triggers.
*
* Unit tests are class methods that verify whether a particular piece
* of code is working properly. Unit test methods take no arguments,
* commit no data to the database, and are flagged with the testMethod
* keyword in the method definition.
*
* All test methods in an organization are executed whenever Apex code is deployed
* to a production organization to confirm correctness, ensure code
* coverage, and prevent regressions. All Apex classes are
* required to have at least 75% code coverage in order to be deployed
* to a production organization. In addition, all triggers must have some code coverage.
*
* The @isTest class annotation indicates this class only contains test
* methods. Classes defined with the @isTest annotation do not count against
* the organization size limit for all Apex scripts.
*
* See the Apex Language Reference for more information about Testing and Code Coverage.
*/
@isTest
private class Account_Create_Contact_TestClass {
static testMethod void myUnitTest() {
Profile p = [SELECT Id FROM Profile WHERE Name = 'BLX Telemarketer' LIMIT 1];
User u = [SELECT Id FROM User WHERE ProfileId = :p.Id AND User.IsActive = true LIMIT 1];
List<Account> accs = new List<Account>();
List<Account> conAccs = new List<Account>();
Set<Id> accIds = new Set<Id>();
Integer i = 0;
System.runAs(u) {
// Test Accounts with no Last Name has been added
for (Account a : [SELECT Id FROM Account LIMIT 50]) {
a.Eerstenaam__c = 'Test First Name';
}
if (!accs.isEmpty()) {
update(accs);
accs.clear();
}
for (Account a : [SELECT Id FROM Account LIMIT 50]) {
accIds.add(a.Id);
a.Eerstenaam__c = 'Test First Name';
a.Achternaam__c = 'Test Last Name';
a.Nieuwsbrieven_ontvangen__c = false;
if (i == 0) {
a.Nieuwsbrieven_Ontvangen__c = true;
a.Dezelfde_Email__c = true;
i = 1;
}
else if (i == 1) {
i = 2;
a.Status_Belactie_2010__c = 'Wil Gebeld Worden Door Account Manager';
a.Opmerkingen__c = 'This is a test Task';
}
else {
a.Achternaam__c = NULL;
}
accs.add(a);
}
if (!accs.isEmpty()) {
update(accs);
}
for (Contact c : [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId IN :accIds AND LastName = 'Test Last Name']) {
Account a = new Account(Id=c.AccountId);
a.Achternaam__c = c.LastName;
conAccs.add(a);
}
if (!conAccs.isEmpty()) {
update(conAccs);
}
}
}
}
Try this code :
Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv
All Answers
Try this code :
Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv
Error: Compile Error: Invalid field anguageLocaleKey for SObject User at line 7 column 153
Make it LanguageLocaleKey, I missed the 'L'.
Let me know how it works out for you.
System.Exception: Assertion Failed: Expected: 111.11, Actual: 999.99
Stack Trace: Class.Update_Opportunity_Amount_TestClass.myUnitTest: line 94, column 1
The error thrown is due to some other class. What you need to do is while deploying your change set is to Run Specified Test instead of running all tests and in the textbox, specify your test class name and then deploy.That ways you wont face any trouble.
Hope this helps!
Please mark this question as Solved if you question was answered here, so that it'll make a proper solution for other community members.
Thanks,
Apoorv