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
2answers
20 views

I am not able to write Test class for below code

I am new to coding and i just want to write test class for this class... public class UpdateAccountAddresses { Map<id,account>updateShippingAddressMap =new Map<id,Account>{}; Map&...
0
votes
0answers
9 views

getting SFSSDupeCatcher error? [on hold]

i am making an unit test for the apex class contains 2 methods . but the developer does not allow to run it show SFSSDupeCatcher can't insert the record. thanks in advance.
0
votes
1answer
13 views

Method does not exist or incorrect signature- Save Process

I am getting an error in my test class stating "Method does not exist or incorrect signature" in the Save Process(). Main Class :- public class AttachmentStatusUsingJSRemotingCtrl { public ...
0
votes
0answers
29 views

my first test class [on hold]

Please correct my test class for the following trigger. Bear with my mistakes plz trigger RecordOwnerChange on user (after update){ if (trigger.isafter & trigger.isupdate){ List<Id> ...
1
vote
0answers
21 views

Global picklist value assignment

When i try to update global picklist value through anonymous window, then this code works great: ActivationTemplate__c acc = new ActivationTemplate__c (id='a034E000001eULQ'); acc.Affiliation__C = '...
2
votes
2answers
37 views

Creating data from tests accessible after tests execution

I would like to gather some info regarding tests execution, e.g. how long execution of different parts of test methods take (e.g. data creation phase, business logic itself, assertion phase). The ...
0
votes
1answer
31 views

How to get code coverage in an if statement

I have 75% coverage. There isn't code coverage for this part of the code if (rsp.Role__c <> Null && rsp.Role__c <> 'Other') { trigger.new[0].addError('...
1
vote
3answers
45 views

Avoiding triggers/flows on managed objects during Apex testing

We are integrating with a managed package that our company bought. We've inserted a custom VF page with an apex controller into their UI and I'm now trying to test the controller. In the constructor ...
2
votes
1answer
33 views

Rolling Limit applies for Test classes?

I am using a test class and getting the error: System.UnexpectedException: ContentPublication Limit exceeded. This is a rolling 24 hour limit. Below is the code: @IsTest private class ...
6
votes
1answer
154 views

Apex Test Setup

I have a test setup method in my test class: class someTest { static boolean ok; @testSetup static void setupTestData() { ... ok = insertSomeTestData(); } ...
0
votes
1answer
12 views

How to run a single test class in Force.com IDE 36.0.0.201601221512 on Mac OS X

When i do a right click on a test class in Force.com IDE then i don't see the option that runs the tests. In previous versions it was possible to run tests of a single test class that way. Does anyone ...
0
votes
3answers
32 views

How to setup test class for this trigger

I am very thick when it comes to setting up test classes. How to set up a test class for a very simple trigger like this? trigger trgr_Key_People on Key_People__c (after insert, after update, after ...
0
votes
0answers
28 views

How to use LastPublishedDate in test classes [duplicate]

How to use LastPublishedDate in test classes, iam using it in Batch class which queries and returns articles which are published 1day before ? while writing test class, i am not getting coverage ...
0
votes
2answers
44 views

Problem Creating test class for Knowledge Article Batch Apex

I Have Batch apex which will send emails when a article was published yesterday(we have scheduled to run daily). I have written testclass for it,but iam getting only 6% coverage.Please help me in ...
2
votes
1answer
43 views

How to use pageMessages and have exceptions in controller tests

So I know how to present an exception as a message to the user: public class MyController { public PageReference myMethod() { try { doSomething(); } catch (Exception e)...
0
votes
1answer
21 views

Test Event Attachment

I'm trying to write a unit test for a method in a class I wrote that attaches a file to an event record. I want to test that if the attachment does not insert give an error, else assert that the ...
1
vote
2answers
14 views

VF Test Class: Pass id to controller at start

My visualforce page is opened via button on a custom object called Employee. Here is the button code: Behavior - Execute JavaScript OnClick JavaScript window.location = 'apex/EmpMerge?hbsId={!...
0
votes
0answers
17 views

Need help on Test class for the following Code please [closed]

Here, trigger copies the field value from Parent object to [Contracts] to Child [Accounts] and Grand Child [Opps]. ` public class OppCalcTrainingSeats{ public static void CalculateSeats(...
0
votes
0answers
10 views

Test class to Run in any Organization(Developer edition/any Sandboxes) for Manged package [duplicate]

1.I have created Managed package 2.In that package, a class method which takes any record ID as Input 3.As a result it gives all Fields names, Fields values and Related object field values of that ...
0
votes
2answers
28 views

Test class to run any Organization

I have a class which takes any record id and returns fields name and it's values as well as relationship record's values. Now to write a Test class, i have to create a record. I can try with inserting ...
4
votes
1answer
73 views

Tools for code Evaluation [closed]

is there any tools to test the logic at what point will hit the saleforce governor limits (applicable only)?? Any sophisticated tools other PMD to evaluate your code against the salesforce best ...
0
votes
0answers
26 views

Unit Test data setup is hitting Apex CPU time limit

I have written a set of methods in a test class that can be called to create and insert relational test data. I am using Test.StartTest() and Test.StopTest() to keep the operations for the test in ...
0
votes
2answers
22 views

I am not able to find how can I achieve the test coverage for the nested classes please help me with the code below:

Here is the class : public class Out { public Meta meta; public Response response; public class In1 { public List<String> COMPANY; public List<String> ...
1
vote
1answer
22 views

VF Test Class - set multi select picklist

How do you pick the values, in a test class, for a multi select pick list? Visualforce: <apex:pageBlockSection title="Licenses:" columns="1" collapsible="false"> <apex:...
0
votes
2answers
22 views

How do I unit test if a user cannot update a field

I added a new method on a trigger that before update on a lead, checks to see if the user is of a specific profile. If they are, it renders an error. It works fine, but how can I write a unit test for ...
2
votes
1answer
21 views

Using Test.loadData with required lookup fields

I have an object with a required lookup field. I want to use Test.loadData() to load hundreds of records from a CSV for unit testing for this object, but I want the unit test to be portable, meaning I ...
0
votes
1answer
16 views

How to test a remote actions which uploads binary data?

I have a method that looks something like the following: public static String uploadFile(String filename, String fileData, String parentId){ String UserId = UserInfo.getUserId(); ...
5
votes
4answers
186 views

Test Class Showing 100% Coverage but APEX Class Is Showing Coverage: None

I wrote my first test class and I am not sure if I am reading the coverage correctly. On the bottom right side, the Overall Code Coverage is at 100%. When I go to my controller, the code coverage drop ...
1
vote
1answer
28 views

Constructor Not Defined Error when writing a test class

I read through other Constructor Error posts but I seem to be missing something, I am writing a test class net new for a class that edits an event that was built by another developer. Previously, I ...
-3
votes
1answer
25 views

How to cover code in test class when use Map [closed]

How can i cover code in the flowing line for class. I am not able to writer for test class for Map as i used Map.key() and Map.Values. I invoked one class in this class as shown below. This is also ...
1
vote
1answer
31 views

Test Wrapper Class

I've read a lot of posts about testing wrapper classes and I still do not seem to understand fully. I have a class that was built by another developer that I am trying to create a test class for. In ...
-4
votes
0answers
19 views

How to write Test class for the below batch class? [closed]

global class Batch_sales_load implements Iterator<AggregateResult> { AggregateResult [] results {get;set;} // tracks which result item is returned Integer index {get; set;} ...
0
votes
1answer
18 views

Unit test where controller gets a visualforce page URL parameter

How can I run a unit test on my controller constructor if it contains the following: originObjectIdString = ApexPages.currentPage().getParameters().get('Id'); When I run the tests, I get an error ...
2
votes
1answer
21 views

How to test selectOption

I have a controller that queries users to be selected in a vf page. I want to write a test class to test the code. The problem is I can't seem to populate the selection in my test so that it goes ...
1
vote
1answer
29 views

Apex Sharing Rule - Test Class - Create sharing error?

I can't quite figure out how to intentionally cause a sharing rule error for my test class. Can someone help me out? Reviewed Name and Reviewer Name are required fields on the page layout. UPDATED ...
2
votes
2answers
74 views

Create AccountHistory record in test class

Can we create the AccountHistory Reocrd in test class if it is possible plz post how ?
-5
votes
0answers
24 views

unit test class for the page reference method in this code [closed]

public PageReference Add (){ boolean duplicate = false; if(UserSelectVAlue != null){ Product2 addedprd = [select id,name, Description, ProductCode, Family from Product2 ...
0
votes
0answers
33 views

Apex Test Class with Open Activities not showing. Why?

So I'm having this weird issue where the code below that I run in Anonymous Window works and I get values in OpenActivities, but when I put the EXACT code in a test class in both @testSetup and @...
1
vote
1answer
24 views

Testing Controller Extension for Visualforce Page

I've recently been writing a few basic controllers for some visual force pages, and of course now need to test them. Problem is I don't really know how. Normally you know you'd instantiate the class, ...
1
vote
1answer
22 views

How to cover the test class for external objects Query in test class

Can anyone suggest me how to cover the SOQL code line in test class. Due to Query failing i am not able to increase the code coverage to 75% minimum for class. Suggest me how can i achieve this . Is ...
2
votes
3answers
45 views

ContentDocumentLink Trigger Test Coverage Issue

I have written a Trigger for ContentDocumentLink and I am trying to write a test class but using Test Class Trigger is not getting covered. Trigger : trigger contentDocumentLinkTrigger on ...
2
votes
1answer
50 views

How to test these class methods, one of which is a remote action?

I have a custom controller with a couple of class methods I'd like to test, one of these class methods is a remote action: global with sharing class MyCustomController { public class ...
0
votes
2answers
48 views

Code coverage for a try-catch block

I was not able to cover few lines from my apex class below: Controller class: public with sharing class Customsave { public Contact contact {get;set;} private String RecordTypeId, ...
3
votes
4answers
116 views

How to throw DML Exception Manually

I've a Apex class as below and i've to write test class for that. trigger SetAccountStatus on job__c (after insert) { List<Account> AccSt = new List<Account_Status__c>(); List<Account&...
0
votes
0answers
26 views

ObjectA.ObjectB__c exists but ObjectA.ObjectB__r does not exist

I am working on a function to update the object related object's fields. e.g. function A () { ObjectA.ObjectB__r.FieldA__c = 1.1; update ObjectA.ObjectB__r; } Now I am writing the test ...
0
votes
1answer
32 views

Unable to fetch host-name and path from CustomUrl?

i am unable to fetch host-name and path from Custom-Url. String value='https://mcnabb--dev.com/_adssd/apex/apexPage'; List<String> abc = new List<String>(); abc = value.split('/'); ...
0
votes
2answers
30 views

How to test instance variables created in the constructor

I'm learning how to write tests for my code and trying to figure what needs to be tested with a custom controller. It seems like maybe nothing but maybe I'm just not thinking about it in the right way....
2
votes
1answer
14 views

Managed packages: does our external app need automated tests?

We're starting to plan out a salesforce app that will connect to our external system. We'd like it to be a managed package down the road. I've been told that our APEX code all needs tests, which is ...
0
votes
1answer
45 views

How to write a test method/class

I have created a simple apex class to be used in conjunction with a visualforce page. Everything is working as I had intended it to in the sandbox and I am now ready to push it over to production. ...
1
vote
1answer
100 views

Many unnested loops cause 'Apex CPU time limit exceeded'

I'm not sure what's happening, but all what I'm trying to do is to write a simple test class which inserting a lot of records. However, my records are related in different relations. My test class ...