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
DreabDreab 

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();
   }
 }
}

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

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

Navatar_DbSupNavatar_DbSup

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. 

This was selected as the best answer
DreabDreab

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..