You need to sign in to do that
Don't have an account?

Error with Apply Unit of Work Principles Trailhead module.
I've tried two bits of code now and I keep getting the error:
Challenge not yet complete in My Trailhead Playground 3
The 'challengeComplete' method in the 'UnitOfWorkTest' class has not successfully passed all tests. Ensure that you run the tests and it passes successfully before attempting this challenge again.
Here's the code I'm trying to run:
//Code attempt #2
public class UnitOfWorkTest {
public static void challengeComplete() {
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(
new Schema.SObjectType[]{
Account.SObjectType,
Contact.SObjectType,
Note.SObjectType});
for (Integer i = 0; i < 100; i++) {
Account acc = new Account(Name = 'TestAcc' + i);
uow.registerNew(acc);
for (Integer j = 0; j < 5; j++) {
Contact c = new Contact(LastName = 'TestContact' + i + '_' + j);
uow.registerNew(c, Contact.AccountId, acc);
Note n = new Note(Title = 'TestNote' + i + '_' + j, Body = 'Test note body.');
uow.registerNew(n, Note.ParentId, acc);
}
}
uow.commitWork();
System.assertEquals(100, [SELECT Id from Account].size());
System.assertEquals(500, [SELECT Id from Contact].size());
System.assertEquals(500, [SELECT Id From Note].size());
}
}
/*My Original Code, attempt #1
public class UnitOfWorkTest {
public static void challengeComplete(){
//Create the unit of work
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(
new Schema.SObjectType[]{
Account.SObjectType,
Contact.SObjectType,
Note.SObjectType
}
);
//Do Some Work!
for(Integer a=[select id from account].size(); a<100; a++){
Account acc = new Account();
acc.Name = 'UoW Test Name' + a;
uow.registerNew(acc);
for(Integer c=0; c<5; c++){
Contact cont = new Contact();
cont.FirstName = 'James ';
cont.LastName = acc.name + c;
uow.registernew(cont, Contact.AccountId, acc);
Note nt = new Note();
nt.title = 'UoW Note #' + c;
nt.Body = 'UoW Body ' + c;
uow.registernew(nt, Note.ParentId, acc);
}
}
//Commit the work to the database
uow.commitWork();
System.assertEquals(100, [select id from account].size());
System.assertEquals(500, [select id from contact].size());
System.assertEquals(500, [select id from note].size());
}
}
*/
Challenge not yet complete in My Trailhead Playground 3
The 'challengeComplete' method in the 'UnitOfWorkTest' class has not successfully passed all tests. Ensure that you run the tests and it passes successfully before attempting this challenge again.
Here's the code I'm trying to run:
//Code attempt #2
public class UnitOfWorkTest {
public static void challengeComplete() {
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(
new Schema.SObjectType[]{
Account.SObjectType,
Contact.SObjectType,
Note.SObjectType});
for (Integer i = 0; i < 100; i++) {
Account acc = new Account(Name = 'TestAcc' + i);
uow.registerNew(acc);
for (Integer j = 0; j < 5; j++) {
Contact c = new Contact(LastName = 'TestContact' + i + '_' + j);
uow.registerNew(c, Contact.AccountId, acc);
Note n = new Note(Title = 'TestNote' + i + '_' + j, Body = 'Test note body.');
uow.registerNew(n, Note.ParentId, acc);
}
}
uow.commitWork();
System.assertEquals(100, [SELECT Id from Account].size());
System.assertEquals(500, [SELECT Id from Contact].size());
System.assertEquals(500, [SELECT Id From Note].size());
}
}
/*My Original Code, attempt #1
public class UnitOfWorkTest {
public static void challengeComplete(){
//Create the unit of work
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(
new Schema.SObjectType[]{
Account.SObjectType,
Contact.SObjectType,
Note.SObjectType
}
);
//Do Some Work!
for(Integer a=[select id from account].size(); a<100; a++){
Account acc = new Account();
acc.Name = 'UoW Test Name' + a;
uow.registerNew(acc);
for(Integer c=0; c<5; c++){
Contact cont = new Contact();
cont.FirstName = 'James ';
cont.LastName = acc.name + c;
uow.registernew(cont, Contact.AccountId, acc);
Note nt = new Note();
nt.title = 'UoW Note #' + c;
nt.Body = 'UoW Body ' + c;
uow.registernew(nt, Note.ParentId, acc);
}
}
//Commit the work to the database
uow.commitWork();
System.assertEquals(100, [select id from account].size());
System.assertEquals(500, [select id from contact].size());
System.assertEquals(500, [select id from note].size());
}
}
*/
If it helps please like and mark as correct as it may help others asking the same.
All Answers
If it helps please like and mark as correct as it may help others asking the same.
If you still face the issue in trailhead.
Please report it here,
https://trailhead.salesforce.com/help?support=home#
https://trailhead.salesforce.com/help
So that our trailhead support engineers will look into it and get back to you.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Regards,
Salesforce Support
I tried that but am now getting this error when trying to run it:
Line: 1, Column: 1
Type is not visible: UnitOfWorkTest