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

Increase my coverage above 70%
Basically Im getting problem after problem, I had to make an Apex class to use as a coustom contoller which all worked well and then I proceeded to "try" and put it on live where I was stopped dead in my tracks because of code coverage after struggling for ages then finally getting an answer on the form I was able to achive 77% coverage. I went to upload to live again and then I got the error :-
After applying a work around my code coverage has dropped to 70% and im really struggling to get the coverage back upto the 75% threshold to even begin testing if the work around does the job. The testing still compleatly confuses me and Im an absolute begginer so I dont know how to format or develop in Apex too well as of yet. Was just hoping if somone can point me in the right direction for gaining the 75% required.
This is my 70% that is covered:-
Here is my Testing Class:-

Thankyou,
Sorry if its super simple and I cant process it.
After applying a work around my code coverage has dropped to 70% and im really struggling to get the coverage back upto the 75% threshold to even begin testing if the work around does the job. The testing still compleatly confuses me and Im an absolute begginer so I dont know how to format or develop in Apex too well as of yet. Was just hoping if somone can point me in the right direction for gaining the 75% required.
This is my 70% that is covered:-
Here is my Testing Class:-
Thankyou,
Sorry if its super simple and I cant process it.
I see that ProgramArea has a look up to Curriculum Area. I have ignored it in this case. But you can add it if you must, similar to my addition of ProgramArea. Fornow, to get things moving, mark that look up relationship as not required.
Your data model is quite complex, you might want to get a Developer on site if things get more hairy.
Updated Controller
Updated Test
All Answers
Check the Logs section of the Developer Console, the one just before the Tests section at the bottom of the screen.
It looks like the insert fails, check the Logs section to see why. I suspect that the Programme_Area__c field is not happy with the 'Test' value, causing the insert to fail. Is Programme_Area__c a picklist field? If so, ensure that you give it a valid option in the test method.
I've been checking your question and I think this is what your test method should look like:
@isTest
static void myUnitTest() {
myController myC = new myController();
// Here you will be setting the value for the required field in the
// record that will be saved by your method.
myC.ApprenticeObj.Programme_Area__c = 'test';
// It's a good practice to wrap your method in test
// by the startTest and stopTest methods
Test.startTest();
myC.saveObjects();
Test.stopTest();
// Finally, do your assertions as you were doing, which is a good practice.
...
}
Please have a look at this and let me know if it makes sense and solves your problem.
Good luck!
Julio
to troubleshoot, you can run the below code in an Annonymous block and can see the insert failure.
Apprentice__c ap = new Apprentice__c();
ap.Programme_Area__c = 'test';
insert a;
My Test Class:
---------------------------
@isTest
public class myControllerTest {
@isTest static public void insertController(){
Apprentice__c a = new Apprentice__c();
a.Programme_area__c = 'test';
insert a;
Apprentceship__c ac = new Apprentceship__c();
ac.Apprentice__c = a.id;
insert ac;
myController my = new myController();
my.saveObjects();
}
}
Im sorry if im being very stupid
Yes, huge difference!!
That means a ProgramArea record must exist, and its ID is meant to go in the Programme_Area__c field.
As it is, I expect that even your visualforce page and controller are no longer valid.
Share with us all the fields of the ProgramArea object and we'll help you update your code.
And no, you are not being stupid.
I see that ProgramArea has a look up to Curriculum Area. I have ignored it in this case. But you can add it if you must, similar to my addition of ProgramArea. Fornow, to get things moving, mark that look up relationship as not required.
Your data model is quite complex, you might want to get a Developer on site if things get more hairy.
Updated Controller
Updated Test
Hopfully this is my last question but this is whats stopping me from going live, what do I add? Thankyou
The error states that you are missing a required field in line 16 of the controller.
line 16 is the one that inserts ComponentsObj.
The required field, according to the error message is Apprenticeship_Qualifications__c.
With that established, add the following line to the controller, just above the insert ComponentsObj
FYI, I used 'Test' but if that field is a picklist then the actual value should be one of the existing options in the picklist.
The complete controller class becomes Remember to use valid picklist options where applicable.