You need to sign in to do that
Don't have an account?
Test Method Help for a Newbie
This is likely very basic stuff to an experienced person but unfortunelty that I am not..
I've spent hours on trying to put together a test method for this controller to override the standard save method.
Any help would be greatly appreciated.
---------------------------------------------
public with sharing class myslider {
Client_Assessment__c Assessment;
public myslider(ApexPages.StandardController controller)
{
Assessment =(Client_Assessment__c )controller.getRecord();
}
public void saveme()
{
update Assessment;
}
/**
* Code coverage for saveme action
*/
public static testMethod void testSaveAction()
{
//Setup User
User u1 = [select id from User where alias='dreab'];
//Run As U1
System.RunAs(u1)
{
Test.startTest();
Test.stopTest();
}
}
}
Hi,
Try the below code snippet as reference. It’s Code Coverage 100%
/**
* Code coverage for saveme action
*/
public static testMethod void testSaveAction()
{
Client_Assessment__c ca=new Client_Assessment__c();
ca.Name='dummy';
insert ca;
ApexPages.StandardController sc = new ApexPages.standardController(ca);
myslider obj = new myslider(sc);
obj.saveme();
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
Try the below code snippet as reference. It’s Code Coverage 100%
/**
* Code coverage for saveme action
*/
public static testMethod void testSaveAction()
{
Client_Assessment__c ca=new Client_Assessment__c();
ca.Name='dummy';
insert ca;
ApexPages.StandardController sc = new ApexPages.standardController(ca);
myslider obj = new myslider(sc);
obj.saveme();
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thank you for the assist !
I used your recommendation however I wanted to insert and validate a trial account test method. When I tried to insert an account it failed. Couldn't figure it out when I finally realized I was using "Person" accounts, apparently when using person accounts you have to specifically set the recordtype before insert.
All is well, thanks again..