A unit test is code that is written and executed to test a specific portion/unit of source code. Unit tests are class methods with the testMethod modifier or @isTest annotation and are usually placed in separate test classes annotated with the @isTest annotation. Code that is executed by unit ...

learn more… | top users | synonyms (3)

0
votes
1answer
15 views

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PG_CountryId: execution of BeforeInsert

@isTest private class PG_teststaffscoursecontroller{ public static PG_SupportedCountry__c country = new PG_SupportedCountry__c(); public static PG_SubRole__c sub = new PG_SubRole__c(); ...
-1
votes
0answers
14 views

TEST CLASS ApexPages.Standard.SetController [HELP]

public ApexPages.StandardSetController soSetCon { get { if (this.soSetCon == null) { this.soSetCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id ...
0
votes
2answers
24 views

Unexpected Behavior in Unit Test

I'm running into a somewhat bizarre situation when trying to run unit tests for my apex code. The functionality is that when a contact is created, a child record of a custom object is also created and ...
1
vote
2answers
38 views

Test Not Covering All My Trigger Code

I have created a trigger that fires when a Task is Inserted, Updated, or Deleted. When it fires, it updates custom checkboxes on open Opportunities based upon the Subject of the Task and checks to ...
0
votes
0answers
27 views

Help with Inserting an Opportunity in a TEST Class for Code Coverage

I'm having issues with an APEX test class to provide code coverage to a Trigger I created. Here is the code of the Trigger. trigger UpdateOpportunity on Opportunity (before insert, before update){ ...
0
votes
1answer
15 views

How to do multiple actions in unit test - After Insert, After Update, After Delete

I'm trying to write a unit test for my trigger, which operates on After Insert, After Update, After Delete. The trigger works great in real life, but I can't get the unit test to do what I want. The ...
0
votes
1answer
13 views

Attempt to de-reference a null object in apex class

I am getting the following error: System.NullPointerException: Attempt to de-reference a null object Stack Trace: Class.unsubscribe_user.unsubscribeMe: line 21, column 1 ...
-2
votes
1answer
32 views

How to write test class . please help me [closed]

How to write test class for this. how can i populate account look up in case object while creating a case object how can i get id please help me Public class CustomCaseAlertsController{ public ...
1
vote
2answers
26 views

How to test page messages in unit test?

I have an Apex controller which unsubscirbes users from email via an opt-out form. I have written a test class which tests the method (or atleast partially at the moment). I would like to know how I ...
0
votes
0answers
36 views

Gaining code coverage in my Apex Test Class

I have created a test class for my custom apex controller used my force.com website. I have attempted to create the test covering as many lines as possible from assuming what lines need to be covered, ...
0
votes
0answers
20 views

I have a test class, but it doesn't show up on the selection list in developer console or the Salesforce UI.

my test class has the directive of '@isTest (seeAllData = true)' and my methods are like: static testMethod void TestContoller_InsertLineItems() but still the file doesn't show up in the selection ...
0
votes
1answer
51 views

TestClass without seealldata=true

I have written a TestClass for a trigger which basically throws an exception if more than the specified number of incidents are opened for a single user at any given point of time. In my TestClass I ...
-1
votes
0answers
17 views

how to write test class for this apex class [closed]

public without sharing class PG_StaffsCourseController extends PG_BaseController{ public PG_SubRole__c subrole; public User user; public Boolean showhide {get;set;} public Boolean ...
1
vote
1answer
58 views

Test Class for Visualforce Extension - Wrapper Classes Issue

I'm trying to write test class for a visualforce extension. The extension is designed to use wrappers to add actions (Action__c) to a parent object Activity__c. The actions are child objects and the ...
1
vote
2answers
43 views

Apex tests stalling, nothing will run

In sandbox, I have an issue getting any tests to run at all. No matter what the test, or whether I start it from Apex Test Execution or the dev console, it stalls out in the 'Queue' status. If I ...
1
vote
1answer
20 views

Does installing a new version of a managed package in a production org run tests that are not in the managed package?

We need to install a new version of a managed package that is already installed in our production org. I know that the developer of the managed package can opt to not run tests that are part of the ...
1
vote
0answers
19 views

How to test that a warning was generated

In one of the classes I need to support, there is a need to fetch additional data for a record. There is a function allowing the pre-fetching of data for multiple records to support bulkified ...
1
vote
1answer
38 views

how to write test class for running user

Below is my test class in salesforce apex:- @isTest public class Testopoffers{ @isTest private static void testRun(){ Contact c = new Contact(AccountId = '001g000000OPOr1',LastName = ...
0
votes
0answers
15 views

SOSL in Test class always returning empty

I have the below class @isTest private class SOSLTestClass { @isTest static void test_method_one() { Account accObj1 = new Account(Name='test'); Account accObj2 = new ...
2
votes
1answer
28 views

Apex Test Class - Limits Query

This is a newbie question. Let us assume that I have the following test class @isTest class xyz { @isTest static void method1() {...code..} @isTest static void method2() {...code..} @isTest ...
0
votes
1answer
30 views

Code coverage Drop query

Heres my apex class(from the doc) public class TVRemoteControl { Integer volume; static final Integer MAX_VOLUME = 50; public TVRemoteControl(Integer v) { volume = v; } ...
2
votes
4answers
136 views

Apex Test Execution Stuck in Queue

I have attempting to run an Apex Test Execution and my test has been stuck in "Queue" since yesterday. It doesn't look as though I , as the Admin, have been locked but still no progress on the queue. ...
0
votes
1answer
27 views

Test Class Error on Trigger UNKNOWN_EXCEPTION

so I'm getting this error below. Seems like its pretty explanatory right? The thing is that I have another class that actually inserts the user, and the test class on that works fine. All this trigger ...
-2
votes
1answer
19 views

I have trigger and i have written test class for this its showing 46% how do cover the test coverage

trigger creatingMenuDetails on Opportunities__c (after insert,after update) { list<Menu_Detail__c> MD=new list<Menu_Detail__c>(); for(Opportunities__c op:trigger.new) { ...
2
votes
1answer
29 views

Prevent trigger from running in single test

Ok so I have a fairly complex scenario I need to test... I have a Trigger on a MyObject__c that creates PermissionSetAssigments when MyObject__c is inserted. Because PS Assignments are system ...
1
vote
1answer
33 views

Test Class Guidance (What, not How)

I have the following extension class that I'm using to build a visual force page. It is intended to display a filtered list of Campaign History, rather than the existing related list. It works. ...
3
votes
1answer
52 views

Custom Setting issue in Test Class

I have written a pretty simple VF page that allows support users to add Case Assists (custom object related to Case) to their case. Pretty simple VF page, when opened, it creates a list of a wrapper ...
-1
votes
0answers
24 views

This trigger sets the owner of the account record type to be the same as the owner of the other account record type

I need to write test class for this can anyone help me out how to achive this . trigger accountRecOwnerUpdate on Account (before insert) { // This trigger sets the owner of the account record to ...
1
vote
2answers
35 views

Unit Test visibility: Account vs User Object

I just started learning the salesforce apex coding from the link and wondering why the below method can access User object but not Account object? // Test method that has access to only the data it ...
1
vote
1answer
22 views

How to select one field from one table in apex class?

I have an apex class with some code like this: public List<Product2> myList{ get{ myList = [Select p.url__c, p.ProductCode, p.Nom_du_produit_2__c, p.Description From Product2 p ...
0
votes
0answers
41 views

Unit test class v32 on Spring 15 start failing because 'SELECT FROM ContentVersion' doesn't return any records

Here is the extract from unit test. It works for api version <32, but for v32 on Spring 15 env 'SELECT FROM ContentVersion' return nothing and as result unit test fails. //create initial ...
0
votes
1answer
12 views

Testing DMLException in future method

Any ideas how I can test this one - only the DMLException and Exception parts @future public static void updateUserFlags(Set<Id> userIds ) { Logger.log(ShGl_Constants.INFO, ...
1
vote
1answer
24 views

Unable to create OpportunityLineItem objects while unit testing the code

I have a Controller extension on Opportunity object that I am trying to test using unit tests. The code (see below), inserts all the data appropriately in the database. However when I try to print to ...
2
votes
2answers
84 views

If I create and insert a user within test method, does it affect Salesforce user licenses?

I know that users are not considered as data in test classes. For example, I can still fetch a user from database, even if the test has SeeAllData=false annotation. How about creating and inserting a ...
1
vote
1answer
19 views

test method to test for LimitException

I want to simulate LimitException error on StandardSetController which can only return max 10000 records. So I am trying to create a test method which creates more than 10000 records and then try to ...
0
votes
0answers
24 views

How to write test class for Try catch block for below code

public void save() { if (user.contact != null) { setContactFields(user.contact); } try { update user; if (user.contact != ...
3
votes
3answers
163 views

What is the best practice for initializing test data for multiple test methods?

When you are writing multiple testMethods that ultimately start with the same test data, what is the best design for those initilization methods? By best design, I mean what are the implications for ...
1
vote
2answers
207 views

Trivial batch job in test failing

I have a scenario where a trigger should take certain actions based on the number of Contacts assigned to an Account: If a Contact has no account assigned it will look for a special "Unassigned" ...
0
votes
1answer
36 views

getting error in test class “System.NullPointerException: Attempt to de-reference a null object”

getting error in test class "System.NullPointerException: Attempt to de-reference a null object" "Class.TesttriggeronoppandquoteUpdate.myUnitTest1: line 13, column 1" i have created this ...
0
votes
2answers
29 views

Writing test for before delete trigger

I have a trigger that fires when a user tries to delete a child object that is associated to a parent object. So, in my test class, I set up my child and parent objects and relate them. Then I try to ...
0
votes
1answer
35 views

Does HttpCalloutMock work when the tested method doesn't return HttpResponse?

UPDATED: I've included the unit test. I'm trying to test a Visualforce extension method that does a callout but returns a PageReference, not an HttpResponse. I'm finding that the HttpCalloutMock ...
1
vote
2answers
69 views

Compile Error: Constructor not defined: [MyController].<Constructor>(ApexPages.StandardController)

Can I get some help with my test class for my visualforce page? The page lists contacts and then the controller creates an activity for each contact selected after a button is clicked. I am ...
0
votes
0answers
40 views

Apex unit test for new record fields

I can't seem to get code coverage on the following lines of code. Probably overlooking something but could use extra pair of eyes. this.AuditAutoVehicle.Liability__c = ...
1
vote
1answer
40 views

Test Class for Custom Controller

I'm having trouble writing a test class for a custom controller used in an VF page. The goal is a UI allowing the creation of multiple records for a Custom Object Time_item__c. Everything works as ...
0
votes
2answers
31 views

Need help with Apex test code

So, Ive managed to learn a bit of Apex code. Now I need help with associated test code. Could someone please help me get started? public class multiAddCEx { public Id cID = ...
1
vote
2answers
37 views

INVALID_CROSS_REFERENCE_KEY Exception

I keep getting this error when running a Test Class and I just don't know where to go from here. I've tried disabling Parrallel Apex Testing, running the code as a standard user, etc. I must be ...
2
votes
0answers
25 views

Testing scheduled apex containing @future method?

I've seen plenty of posts and documentation on testing asynchronous apex in general, but what about code with multiple layers of asynchronous code? Specifically, I have a scheduled apex class which ...
2
votes
3answers
75 views

Can't get code coverage over 75% when deploying to production [closed]

I have been struggling with this for 5 hours now and can't find a solution. I am trying to push my code from the sandbox to production but when I try to validate the deployment in the production ...
-2
votes
2answers
63 views

Test class for Wrapper Class [closed]

I have tried this but getting an this Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace Class.Hos_Vol_MultiAdd.: line 72, column 1 ...
0
votes
2answers
53 views

Only Getting 40% Code coverage on Trigger Please Help!

I'm trying to update a lookup field on the lead object via trigger, but I'm not getting enough code coverage. Can someone help me ? TRIGGER trigger PartnerName on Lead (before insert) { ...