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)

3
votes
2answers
48 views

Member variable null after being set from subclass

Before I start, I realize a possible solution here is to have InnerClass explicitly reference the testString variable in the Inherited class like such: In the constructor: OuterClass o = oc; In ...
9
votes
1answer
114 views

Why use Test.setCurrentPage() method in a unit test?

What is the purpose of the Test.setCurrentPage(..) method and why would I use it in my apex controller unit tests? According to the salesforce docs, ...
2
votes
0answers
33 views

Test method related to Content fails during Deployment, but not when run all test is run

I am facing issues in deploying a change set. This contains one page and class. None of the components are new. There is a slight change in these two components. When I deploy, an unrelated class ...
2
votes
1answer
30 views

Unit Test for Controller that Calls a Flow

I have a controller that initiates a flow when a button is clicked on a lead. I understand that unit test classes cannot make web callouts, so I have created a class that implements the ...
1
vote
1answer
38 views

Apex class for trigger

I am writing a test class for Contact record update trigger I tried my best but it's not working, please check and give suggestion to improve my code @isTest public class TestStopEmails { static ...
0
votes
1answer
24 views

Test Class for Extension including a SOQL query

I wrote the following class and it does what I expect it do on the vf page in Sandbox and so I started a test class but then my lack of apex knowledge and coding experience caught up with me. Please ...
3
votes
1answer
32 views

Mixed DML in Test Method

I followed the steps to use runAs but it is still giving me a mixed_dml exception. I need to populate the contactId so the user has to have a portal profile. Here's what I have for the test method ...
3
votes
1answer
26 views

Testing @future method Failed Assertion

I have some code that after inserting a task, calls an @future method to update some fields on the contact linked to that task (WhoId). This seems to work fine in sandbox, but I can't seem to get it ...
1
vote
2answers
22 views

How to create a case object with caseNumber field in test method?

I need to create a case Object with case Number assigned to it in my test class public static Case CreateCase(Id conId,Id accId){ Case caseObj = new Case( ContactId = conID, AccountId = ...
1
vote
1answer
102 views

Attempt to De-Reference a null object won't except data

I have an issue when I try to input data into a custom object. On line 14 is where I'm getting the NullPointer. System.debug(testAccount[0].name) outputs an account name created in line 8. But when ...
-2
votes
0answers
23 views

Error in Test Class :Quote has no pricebook assigned

Can any one help me out with this Error : System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The pricebook entry is in a different pricebook ...
2
votes
0answers
35 views

Unable to retrieve related records in Test Class using SOQL

The following SOQL in test classes gives a list of contacts but it doesn't lists any related account fields. List<Contact> contacts = new List<Contact>([Select Id, Email, AccountId, ...
-1
votes
0answers
29 views

Need help to make 46% Code Coverage to 75% for Test Class [closed]

Below is my Controller Test Class : @isTest(seeAllData=true) private class SAPPartsSearchControllerV3TestClass { static testMethod void myUnitTest() { Test.StartTest(); SAPPartsSearchControllerV3 ...
1
vote
1answer
58 views

Apex unit tests taking very long time to execute inside Salesforce

I've written several simple Apex unit tests and I'm trying to run them through Salesforce, so: Setup > Develop > Apex Test Execution > Select Test... > Run The tests are passing, the ...
-1
votes
1answer
49 views

I'm only getting 24% coverage, any ideas on how to increase my coverage? Thanks! [closed]

@isTest private class TestOliWizard { static Opportunity opp; static PriceBook2 p; static Product2 pb; static testMethod void testWizardWithPriceBook() { setupData(); opp.Pricebook2Id = [Select ...
2
votes
2answers
48 views

UNABLE_TO_LOCK_ROW error in parallel apex tests

i get an UNABLE_TO_LOCK_ROW error when running my tests in parallel. The error occurs when creating a pricebookentry for the standard pricebook. As far as i know Salesforce locks also the parent ...
5
votes
1answer
41 views

How do governing limits work with @testSetup from Spring 15' release

The new @testSetup method is covered pretty well by Jesse Altman in his: New Spring ’15 Feature: @testSetup article but as mentioned in the comments, there is a question about how this new feature ...
2
votes
1answer
21 views

Can anyone explain this 'variable does not exist error'?

I have a test class which calls a method from a helper class : @isTest private class OpportunityCheckTest { private CheckTestHelper helper = new CheckTestHelper(); @isTest static void ...
-2
votes
2answers
31 views

How to call n no of USER profiles in test class

Can any one help me out how to call 'n' no of USER profiles in test class.Any help very much appreciated. Trigger : trigger oli_multiple_products_before_insert on OpportunityLineItem (before ...
0
votes
1answer
56 views

How to Create Opportunity Line Items in Test Classes

All the test classes are on opportunitylineitem. I tried testing each test classes all are running with code coverage more than 75% in sandbox as well as production. When I try to migrate the newly ...
0
votes
0answers
39 views

Need some help please with pagination testing

I have 69% coverage on my controller, everything is covered accept the pagination. I need some guidance as I'm pretty new to Apex this is my second controller I've ever written. I will include the ...
0
votes
0answers
31 views

Can we use : Disable parallel apex testing option in production [duplicate]

Can any one help me out? On opportunitylineitem there are triggers and apex classes. Now I have written another trigger on the same class. All the test classes have above 75% code coverage. The ...
-1
votes
0answers
51 views

System.DmlException: Insert failed CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY,at production

Can any one help me out with this Errors.I have a trigger on opportunitylineitem and written a test class.When I deploy the trigger I get different Error .Any help very much appreciated. All the ...
0
votes
2answers
73 views

help to get 17% to 100% for batch class

I am new in SFDC i need to get 100% code coverage for this batch class currently it has 17% and i am facing problem in every Messaging.SingleEmailMessage mail = new ...
3
votes
2answers
45 views

Writing Test Class for Apex Email Batch Job

I need help writing test cases for an email batch job. In the batch job, the users associated with the Franchisee__c field (a Lookup to User) from the custom object Store_App_Proc__c are selected and ...
2
votes
2answers
32 views

OpportunityLineItem in test classes

I am trying to insert OpportunityLineItem record in my test class but unable to insert. Account acc = new Account(Name = 'Test'); insert acc; Opportunity oppObj = new Opportunity(Name = ...
0
votes
2answers
30 views

Apex Trigger Test Class Issue

I wrote a trigger that works, and wrote a test class, but for some reason in the developer console in the code coverage list my trigger doesn't show up. When I tried to deploy the trigger to ...
0
votes
2answers
47 views

Test class Code coverage gets varied

Can any one let me know why the test class code coverage gets varied. 1)When I test individual testclass (controller) in the sandbox the code coverage shows as 35% only . 2)when I Run all the test ...
0
votes
2answers
66 views

test class for the following trigger?

I am new to write test classes does any one give me idea for follwing trigger? trigger AccountTrigger on Account(after update){ if(Trigger.isAfter && Trigger.isUpdate) { ...
5
votes
2answers
134 views

Variable is not visible in test class

Can any one help me on this Error as **Variable is not visible** in a test class.Any help very much appreciated. Code : public with sharing class InvoiceController { List<wrapperClass> ...
2
votes
1answer
49 views

What's Wrong With This Apex Code (intent - to delete spam Leads)

I'm still pretty new to programming and especially to SalesForce programming, but I would have expected this suite of trigger, handler class, and test class to: test as expected and show the test ...
3
votes
2answers
72 views

Unit Test is Providing 0% Coverage for Apex Trigger

New to Apex here. I cobbled together a trigger that creates a new task whenever a certain type of opportunity is Closed - Lost, but I can't figure out how to get ANY coverage with a unit test. Does ...
-1
votes
1answer
26 views

IF Condition in test class

Can any one help me how to get the IF condition covered in test class.Any help very much appreciated. Code : public List<wrapperClass> getappointmentList1 (){ wrapperClass tempObj1 ...
2
votes
4answers
42 views

Simulate DML error in Unit test

I have a piece of code which upserts some objects. My code is robust enough to handle any DML failures. But i want to test it out in Unit tests. Is there a way i can simulate DML failures? General ...
0
votes
0answers
50 views

Apex Trigger Has 0% Test Coverage - What Am I Doing Wrong Here?

New to Apex here and having trouble getting ANY test coverage on a simple trigger I cobbled together to create new tasks when opportunities are Closed - Lost. Does anyone see what I am doing wrong ...
-3
votes
1answer
40 views

Rollup Summary Fields and Formula Fields are not writable but how to call them in test class

Can any one help me out with test class code coverage .I have written a test class for a controller having wrapper class and their are rollup summary and formula fields which are not writable but how ...
1
vote
1answer
59 views

Approval Process Test Class

I have created a visualforce page which has records of pending approval processes and that page has buttons which approve/ reject a request. Please guide how will I have to write test class for it ...
-1
votes
1answer
19 views

Constructor not defined: [Asia1Activation].<Constructor>() at line 27 column 31

I have a class that looks like this: public class Asia1Activation { public Asia1__c thisAsia1 {get; set;} public Boolean isSuccess {get; set;} public Boolean isActivated {get; set;} ...
-1
votes
2answers
25 views

Issue with Extension Code Coverage

I have an Extension that works perfectly but the Test Class only has 65% code coverage. I cannot figure out why I don't have 100% (or at least 75%). Any help is greatly appreciated! Extension Class ...
1
vote
1answer
42 views

Test class fails throws different types of error as :STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product

Can any one help me out with test class code coverage .I have written a test class for a controller having wrapper class,but the code covearage is zero. Any help very much appreciated. Different ...
0
votes
2answers
29 views

Trigger not showing up in code coverage list

I created a trigger and in order to deploy it to production it needs at least 1% code coverage. I wrote the test class for the trigger, but I'm having a weird issue where the trigger is not showing up ...
0
votes
1answer
22 views

Attachment Trigger Test Class

Can you please help me with Test Class regarding Attachment Trigger I have. Whenever I run Test Class I get this error below. System.NullPointerException: Attempt to de-reference a null object ...
-1
votes
2answers
29 views

Error Too many SOQL queries: 101 for trigger

I am getting this error Too many SOQL queries: 101 for this trigger when I tried to push it into production. Can anybody please tell what is wrong in the script below. I will really appreciate any ...
2
votes
1answer
35 views

Getting error while inserting test data in test class

I have developed below test class but not getting why i am getting below error, System.NullPointerException: Attempt to de-reference a null object.. the id i am passing has having the value..any ...
-1
votes
2answers
38 views

how to cover catch block in this method in test class

public pagereference savePassword() { if((objAccountTemp.Contact_Name_1__c != null && objAccountTemp.Contact_Name_1__c != '' && objAccountTemp.Affiliate_User_Name__c != null ...
0
votes
0answers
25 views

Test class for a controller having wrapper class,code coverage appears Zero

Can any one help me out with test class code coverage .I have written a test class for a controller having wrapper class,but the code covearage in the test class appears Zero and the overall code ...
-1
votes
0answers
22 views

Code coverage in Test class appears only 4%

Can any one help me out with test class code coverage .I have written a test class for a controller,but the code covearage in the test class appears only 4% and the overall code coverage is 80%. When ...
3
votes
1answer
18 views

What do I assert in this test for a scheduled class?

This is my Scheduler class. global class LeadSummary_Scheduler implements Schedulable{ global void execute(SchedulableContext sc) { getCreatedLeadsSummary gcls = new ...
2
votes
2answers
99 views

Error in test class as : Entity is not api accessible

Can any one let me know why is this ERROR occuring as Error Error: Compile Error: Entity is not api accessible at line 2 column 8 COde @istest Public class TestInvoiceController{ static ...
1
vote
2answers
26 views

Inbound Change set error as:Average test coverage across all Apex Classes and Triggers is 71%

Can any one help me with this Error ,Im facing with these three diffent types of Error. In DC it shows 80% overall coverage in sandbox when we move in to production it say it has only 71% overall ...