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)

1
vote
1answer
28 views

How to Reset a Standard Auto Number Field?

Autonumber field increments when test class runs and note that in Spring14 salesforce has released an option not to increment when test class runs. Develop | Apex Test Execution | Options..., ...
1
vote
0answers
37 views

What are the 10 Principals of Apex Testing? [on hold]

How can Apex Code be tested using Mocking testing principles.
0
votes
1answer
16 views

Testing a List “Searchable” Controller

Will someone please explain, or correct, my testing logic for the following code? The first image is the test, and second image is the code. Here's the test Here's the code Here's the code ...
-1
votes
0answers
6 views

Post Enabling Salesforce Chatter Answer not able to create test class for the added classes [on hold]

We enabled the Chatter Answer feature, Three classes have been added to the organization due to that. As those classes do not have test classes, we have started to develop these. But we are not able ...
0
votes
1answer
20 views

callout error with out callouts in my class

Hi I have below class and test class. I am getting the "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out" error. can u please help me out. ...
1
vote
1answer
28 views

Test coverage for ApprovalProcess

I want to instantiate Approval.ProcessWorkitemRequest in my test class. I am creating Approval process for that. Account objAccount = new Account(Name = 'Test Account',BillingState ='LA'); insert ...
1
vote
0answers
20 views

Process Builder and Test Classes

I have recently set up and activated 4 processes using the process builder to send email reminders (alerts) when records are past the due date. I needed 4 because there are 4 emails send at different ...
4
votes
1answer
81 views

What is a DML Statement?

I know this seems like a really stupid question. But I am still often amazed by the SalesForce platform. Consider the following test: static testMethod void testLimitDmlStatements() { SObject ...
1
vote
2answers
235 views

Code coverage of 93% in sandbox but only 61% in production - won't deploy

I'm doing the first major code deploy in this org. Dev console tests tab shows overall coverage of 93% across all apex Deploying all apex to production Production has only 1 small apex class and ...
2
votes
2answers
41 views

Keep getting this error: System.QueryException: List has no rows for assignment to SObject

I have a Trigger that is referencing a class. It works in Dev, but now I am trying to create the test class in order to push it to production. I am trying to test that a new user is created. I keep ...
2
votes
1answer
27 views

Visualforce Controller Extension Test - Error: Invalid Type

I have created a fairly basic VF page and controller extension class as follows. I am trying to write a test class so that this can be deployed, but keep getting an "invalid type" error in the test ...
1
vote
2answers
20 views

How to set current page URL for testing

I need to test the following piece of code: if (ApexPages.currentPage().getUrl().contains('ActiveParticipant')) Tab1Style = 'activeTab'; How can I set the URL so that the condition evaluates ...
0
votes
1answer
43 views

Need to cover upto 85% [closed]

I written a test class for one class.I am getting 83%. I want to cover 85% or above 85%. can you please help me out to cover 85%. Below are the class and test class.
2
votes
2answers
35 views

Use System.runAs() in a Test Method for calling web service

Everytime I solve a problem, another appears. More than a problem, I would say a SalesForce restrictions. So, I want to test some code (which makes a web service call in order to display some data) ...
3
votes
3answers
61 views

Apex Test Class Help on a Basic Trigger

I have a basic trigger that creates a child record when a parent record is created, and it works perfectly in the Sandbox. But I can't get the Test Class syntax right in order to push to production. ...
-1
votes
0answers
13 views

Help with Writing Test Coverage for HTTP Request Class [closed]

Here is the class I wrote. How could I write test coverage to get 75% code coverage for this: global class ProxyController { public static Http objhttp; public static HttpRequest req ; public static ...
-1
votes
0answers
20 views

testing json parser

I have created a class which helps to automatically update a geolocation field. I have also given the test class but the code coverage is only 72%. below is the code and test class. The lines of code ...
-4
votes
0answers
23 views

Test Class for my trigger [closed]

Below is my trigger. Trigger working fine. I need testclass for my trigger. trigger CreateChargeCodeAutomatically on MPM4_BASE__Milestone1_Project__c (after insert) { Set<Id> ...
1
vote
2answers
30 views

how to access static method in test class

Controller Name : Rforce_TaskUtils_CLS My controller has a method as public static void onAfterInsert(list <Task> listtask, boolean isInsert, Map <Id, Task> oldMap ) In my test clas, ...
0
votes
0answers
31 views

How to define two methods in test class?

My apex class code : /* this is for after insert */ public with sharing class Rforce_TaskUtils_CLS { public static void onAfterInsert(list <Task> listtask, boolean isInsert, Map <Id, ...
0
votes
1answer
44 views

Help Writing a Simple Test Class

How in the WORLD do I write a test class around this code? I've been able to get a successful test run, but the test says I have no code coverage. All this code does is take 5 text inputs passed in ...
1
vote
1answer
18 views

Standard pricebook returns unexpected results in test class

In my test class I insert new products and pricebookentries, in my test class I don't use seeAllDate=true annotation and in order to retrieve standard pricebook id I used Test.getStandardPricebookId() ...
3
votes
1answer
28 views

Is there a way to identify classes that are short on test coverage?

In an org with many classes, controllers and triggers, is there a way to quickly identify where code coverage is low? Run all tests shows me where there are tests that are failing, but there doesn't ...
-8
votes
0answers
18 views

Defining the arguments in test class [closed]

In the apex class , a method has the following signature: public static void onAfterInsert(list <Task> listtask, boolean isInsert, Map <Id, Task> oldMap () I have to define these ...
0
votes
2answers
36 views

Can't create a page for testing

I'm trying to create a page in my test class like this: PageReference pageRef = Page.testPage; Test.setCurrentPage(pageRef); But I'm getting an error: Compilation error: Page testPage does ...
0
votes
1answer
33 views

QueryException: List has no rows for assignment in test class

I have included the following code and dependencies (fields) in my change set and I'm encountering the following error: LeadCreateOppTrigger.LeadCreateOppTrigger(), Details: ...
3
votes
1answer
38 views

NULL lookup field in Test Class

I'm getting a null value on a lookup field when running a test class. Account a = new Account(Name = '1', Owner = u, CurrencyIsoCode = 'CAD'); insert a; a = [SELECT id, AccountNumber, Name, ...
1
vote
1answer
22 views

Compilation error with a unit test

I'm trying to write a unit test for my Timeline apex class but I keep getting an error: "Compilation error: Constructor not defined:[Timeline].<Constructor>". @isTest public class TimelineTest ...
0
votes
0answers
22 views

Bounce email and email limit handle in apex

I have a list of emails. There is a wrong email address in it. i want to send email message to other address by avoiding wrong address in the list. so how can i do? problem: when i did that all ...
0
votes
1answer
23 views

How to handle email bounce and Email limit exceeded in salesforce using apex

How to handle email bounce and Email limit exceeded in salesforce. I am new in salesforce. I try too much but can not rid-off. So how to handle these problems.
1
vote
1answer
23 views

Test class error - Field is not writeable: OpportunityPartner.OpportunityId

I am trying to write a test class for a tigger and ansure why I am getting the following error - Field is not writeable: OpportunityPartner.OpportunityId at line 40 column 68 // test 2: ...
1
vote
2answers
20 views

Success when deploy with Out bound change set, fail with deploy with Force.com IDE or Mavensmate

So this is been going on for a while. Everything works when I use the build in outbound/inbound change set to deploy code form Sandbox to Production. And Fails every time trying to deploy the exact ...
0
votes
1answer
37 views

How to achieve 75% code coverage? [closed]

Hi below are the class and test class. Apex Class: global class GE_PRM_Count_Active_Partner_Users implements Schedulable { global void execute(SchedulableContext ctx) { ...
5
votes
1answer
39 views

Apex Testing Query : System.FinalException: Testing already started

@isTest public class CaseUtilityTest { @isTest static void TestCreateCase() { Test.startTest(); CaseUtility.CreateCase(100,false); // 1 Test.stopTest(); ...
2
votes
1answer
12 views

Packaging & Uploading a ChatterMessage (“Chatter private message”) trigger

I'm facing an interesting scenario. Spring 15 introduced the ability to "moderate" Chatter private messages. Basically, we can now create triggers on the ChatterMessage object. I coded a trigger and ...
3
votes
1answer
37 views

Mock Testing with Named Credentials

I've successfully implemented Named Credentials for a Basic Auth integration callout. However, when I went to write my test method, I noticed one minor annoyance. When I try to create a ...
3
votes
2answers
45 views

Test class for trigger afterUpdate executes only once?

I have a trigger on Account object as : AccountTrigger.trigger: trigger AccountTrigger on Account (after insert, after update, before insert, before update) { ...
2
votes
0answers
39 views

Unit tests for managed package fail in target org after install

Some unit tests for our managed package fail in a target org when run after installation. The same tests run fine in our patch development org, and the package also installs without problems. It's ...
2
votes
2answers
62 views

Why does my newly created Account object in a Unit Test not have the expected field default values?

I created a field on the Account object called In_Negotiation__c, it's a picklist with options 'True' and 'False' with a default value of 'False'. (Yes, I know it would make more sense to have it be ...
0
votes
0answers
28 views

Deep Clone Test Class not finding newly created record

I have a deep clone class that is called from a VF page. The class executes perfectly, I just cannot get my test class to work properly. I'm trying to verify that the cloned record is created within ...
1
vote
0answers
25 views

Test Class: How to Create an Outbound EmailMessage?

Is it possible to completely replicate in a unit test creating an outbound emailmessage record against a Case? By that I mean including the Task creation. I've tried the below in a test class (and ...
-1
votes
1answer
41 views

How to Write a Test Class for Webservice Class?

Situation I wrote a web service class. From my understanding unit tests in salesforce are supposed to test the whole functionality (end to end). But I don't know how to test this external interface. ...
3
votes
2answers
66 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 ...
11
votes
1answer
158 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, ...
3
votes
0answers
39 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
35 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
40 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
26 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
36 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
30 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 ...