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 (2)

2
votes
1answer
15 views

Test Class is not working for Map in class

I am not able to get coverage for the Maps in the class. I only getting 54% coverage and don't know what else to try. Can anyone please help me here. I will truly appreciate it! public with sharing ...
-1
votes
0answers
17 views

How to write test class for the following trigger? [on hold]

//This trigger does not allow to delete an opportunity under an account if there is only one opportunity trigger deletingOpportunity on Opportunity (before delete) { // For every Opportunity record, ...
0
votes
2answers
18 views

Inserting test data using a list or a map to reduce the number of DMLs and get different Ids for different tests

Refer to below test class, @isTest public with sharing class CategoryHelperTest { private static boolean testDataCreated = false; private static Scheme__c ss; private static ...
0
votes
2answers
32 views

Apex Test Class - After Update Trigger

I have a test class that is only covering my trigger 48% and I want to get it as close to 100% as possible. It appears there is one section that I am not covering when using the Developer Console but ...
0
votes
2answers
30 views

Problem in System.assertEquals method [on hold]

I am writing test class in which I'm inserting 5 custom objects. My question is that do i need to add System.asertEquals for each and every object or to add to any one is sufficient.
0
votes
2answers
17 views

Inserting test data using a list to reduce the number of DMLs

I got the below test class, @isTest public with sharing class CategoryHelperTest { private static boolean testDataCreated = false; private static Scheme__c ss; private static ...
1
vote
1answer
195 views

How to write test coverage for private method in controller?

How can I test private methods in an apex controller ? For instance this example: private static string getUserId(String str){ string UserId = ''; if(ref != null){ ...
0
votes
1answer
24 views

Does anyone recognize this error message pop up in Salesforce?

I'm trying to run some tests in the Salesforce 'Apex Test Execution' page and suddenly this error message has popped up, it keeps appearing when I press the 'Select Tests...' button. Has anyone seen ...
1
vote
1answer
29 views

System.NullPointerException: Argument cannot be null

Im getting the error 'System.NullPointerException: Argument cannot be null' when I run my test class, in the below test method. /* * update a existing report */ static testMethod void ...
0
votes
1answer
23 views

test class is not covering email messaging

trigger: trigger TaskCompletion on Task (after insert,after update){ IF(trigger.isinsert){ for (Task E : Trigger.new){ If((E.CreatedById != ...
0
votes
0answers
22 views

Help regarding test case code coverage

public with sharing class searchpn { //variables Public Id parentId; public Integer qliRowNum1{get;set;} public Integer qliRowNum{get;set;} public Integer finalRowNum{get;set;} ...
1
vote
3answers
55 views

0% code coverage Test APEX class

I have set up a simple APEX class that is an extension for a Visualforce page. The VF page has a commandButton that saves and takes you to a different page called "Congratulations.vfp" I have been ...
1
vote
1answer
30 views

APEX Unit tests hello world

I am trying to learn how to do APEX testing but all the tests in the documentation are too complex and I can't find an example of a simple APEX Controller that is a Hello World Test. I have this APEX ...
2
votes
1answer
30 views

How to use Pattern matching in test class for email field?

I am using pattern matchers for the email filed in contact in my development. When writting the test i am getting error in that patter matches.Here i have method the error line.Kindly help me to ...
-2
votes
1answer
30 views

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING in test class

Class: public class CreatePurchaseorder{ public Purchase_order_setting__c pos {get;set;} public boolean isInput{get;set;} public id poid{get;set;} public boolean isUpdt{get;set;} ...
0
votes
1answer
28 views

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

public with sharing class TaskController { Public String PageId{get;set;} Public Task Task{get;set;} public TaskController(ApexPages.StandardController controller) { ...
4
votes
0answers
46 views
+50

Creating Idea Votes from portal user in Test code. DML Exception

I Wrote a very simple VF Page and Controller to show the Accounts that voted on certain Ideas. Here is the controller. Just aggregates the Up and Down votes on the Idea excluding internal votes. ...
-1
votes
0answers
31 views

sales force test class

i wrote one class and for that test class also created.. class: public class FRsubPrjCtrl{ Public Project__c pln{get;set;} public Allocation_amount__c sub; public ...
0
votes
2answers
22 views

VF Controller Test Class

I have been trying to create a test class for my controller for my visual force page and I am not grasping the concepts behind it, can someone help me get started? I have tried a few things but I have ...
2
votes
1answer
41 views

I have this trigger and test class . why my test class cover 0%

trigger openTrigger on Project_Item__c (after insert,after update,after delete,after undelete) { Project_Item__c[] items; //Use Trigger.old For After Delete and The Others is Trigger.new ...
0
votes
0answers
42 views

Incorrect code coverage in developer console

I have an apex class called RelationshipTreeController (RTC for short) and a test class called RelationshipTreeControllerTest (RTCT for short). I have written a test method that calls the search() ...
1
vote
1answer
16 views

Need help for custom controller test class

i implemented chatter check in for this blog: http://intmist.wordpress.com/2014/03/23/show-custom-visualforce-page-in-salesforce1-setup-publisher-action-and-check-in-using-salesforce1-app/ do some ...
0
votes
2answers
40 views

how to write a test for read only Page

I have a page emitting XML for outside users. All it does is create xml from the data. I have a problem writing a test to cover it. The page is just: <apex:page showHeader="false" ...
2
votes
1answer
50 views

Passing related objects in tests

I have the following visualforce page: <apex:page standardController="Whatever__c" extensions="WhateverExt" action="{!autoRun}"> <apex:form > <apex:outputField ...
1
vote
2answers
54 views

How can I generate debug logs when I run unit tests from MavensMate?

Generating and viewing debug logs in MavensMate has been clarified before and works great for me - I especially like the Scrub feature. However, I can't generate a log when I run unit tests. To ...
0
votes
1answer
20 views

Test Method to check the error message is displayed in a certain scenario

I got this test method written, static testMethod void test_ValidateImpactCategories(){ Test.startTest(); tester(); ic8 = new Category__c(Name = 'HR',Symbol__c ...
0
votes
1answer
38 views

Getting error CANNOT INSERT UPDATE ENTITY

can anybody help me here. I am not able to push a trigger into production, I am getting this error for all the test.classes. I hope someone can tell me what is wrong here. I will appreciate any help. ...
1
vote
1answer
25 views

Help writing test class for trigger

I need help writing the test class, I am getting only 70%, I don't know what else to do. I will appreciate any help! Trigger Code: trigger updateOSOTrigger on SO_Detail__c (before insert, before ...
2
votes
1answer
42 views

TestMethod SeeAllData defaulting

I have a question about the two examples shown below as it seems that a testMethod defined within a standard class defaults SeeAllData to true whereas when the test method is defined in a separate ...
1
vote
1answer
18 views

Can't resolve 'Method does not exist' error

I have a Controller, roughly as follows: global with sharing class MyController extends OtherController { public static List<Task> getTaskList() { //SOME LOGIC ...
2
votes
2answers
27 views

Sharing Sets and Apex Test Code

Im trying to setup a simple test to show the "sharing set" is working properly. I a communities sharign set that says Account | User:Account = Account:Id | Read/Write and I know this works ...
1
vote
2answers
234 views

How do you test a class that only pulls data

I'm confused by this. When I was using a dev account it allowed me to create classes in Apex Class like this and deploy it with no problem, but now that I'm using our real account it won't let me ...
1
vote
1answer
26 views

Apex Unit testing of Criteria Based Sharing

I have a requirement that uses criteria based sharing. I wish to unit test this requirement. I have seen this SE post that says that we can not test Criteria based sharing and I have seen the help ...
1
vote
0answers
36 views

Weird issue (NEW BUG) with Test.SetMock and body.toString() - Dreaded Uncommitted work pending

Using test.setMock between test.startTest and test.stopTest DML performs fine everywhere except: This code fails unless the insert is not done: sr = [Select Body From StaticResource Where Name = ...
0
votes
0answers
49 views

Get test coverage on lines that won't execute if Test.isRunningTest() is true

I was trying to write a test class for one of my classes. It has a condition which checks for whether the run is a test run or not. try { if(!test.isrunningtest()) { ...
-1
votes
1answer
52 views

SFDC Test Classes

I've just completed a class writing and need now to create the related TestClass, but this is getting me into some troubles, even If I read several documentation and best practices suggestions about. ...
3
votes
2answers
26 views

Unit testing private sharing

Say I have a class marked without sharing for reading eg Account records without regard to sharing settings. (This would be used in contexts where the current user's privilege level would disallow the ...
0
votes
1answer
55 views

Saleforce Apex Test Coverage

Following is my Apex class: public class lastViewed{ public Datetime cDT; public String LongDate; public String firstname; public String lastname; public String userid; ...
6
votes
1answer
40 views

Error when creating ViewAllData PermissionSet in Apex (for test class)

I can't create a ViewAllData PermissionSet via Apex for a test class. Here is my code: PermissionSet ps = new PermissionSet(name = permSetName, label = permSetName); insert ps; ...
1
vote
1answer
32 views

Using Multipicklist value which is set in Visual force page in Test class

I have a multi select picklist component. The MultiselectPicklist component implements a multiselect picklist similar to that seen when adding tabs to a Force.com application. ...
-2
votes
1answer
39 views

Test Class not covered

This is my code, i wrote test class for this code but it cover only 50% can you please check this code. public with sharing class AccAndCons2 { public list<contactWrapper> Wrappers{get;set;} ...
0
votes
1answer
37 views

HttpCalloutMock in test class fails only if insert an opportunity: You have uncommitted work pending. Please commit or rollback before calling out

Error: You have uncommitted work pending. Please commit or rollback before calling out. Problem: I have a callout request which works only if I don't inserting an opportunity before it in test class. ...
4
votes
2answers
32 views

Is the @IsTest annotation compatible with the global access modifier?

Has anyone wanted to provide a 'Test tool' with a managed package? Something like: @IsTest global class SomeTestHelper { global String findSomething() { return '...'; } } that you ...
2
votes
1answer
33 views

System.LimitException: Too many async jobs enqueued for this apex test context

I'm trying to run with a unit test a batch apex process where I'm calling the same class 5 times. For example: public class MyBatch implements Database.Batchable<SObject> { ... public ...
1
vote
1answer
34 views

TestClass for multiple contacts

This is my main class when i wrote test class for this class i got 41%.i need 75% code coverage for this class. Please check it.. -----Main class------- public with sharing class AccAndCons { ...
0
votes
1answer
29 views

Unit Test User Context?

I'm implementing Communities and need to improve my org's security settings. I set Accounts to be private with a sharing rule of "Owner in all internal users" is shared with "All internal users". One ...
1
vote
2answers
38 views

De-Reference Null Object

I am reusing some old code here - i've made slight changes but the code itslef is so old it contained the test class within the main class. I have seperated them out but I am getting a pile of errors ...
2
votes
2answers
61 views

Can't upload test class

I accidentally (but successfully) uploaded to production via change set an Apex Trigger, without also uploading a Apex Test Class (doh!). I have the test class created and ready to deploy, but I'm ...
3
votes
1answer
20 views

Account Showing as Null after insert during a test

I have written a helper class which is called from a trigger and a test to test it however my test isn't getting full coverage as it is showing the account attached to the asset is null however ...
1
vote
3answers
46 views

Illegal assigment from LIST<custom_object>

I am fairly new to Salesforce, I have a trigger which requires a test method for it to meet its code coverage. I am getting errors in the test class stating Error: Compile Error: Illegal ...