Tagged Questions

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)

4
votes
0answers
27 views

deserializing JSON to object: different behavior in unit test vs API?

So let's say I've got a class that looks like this: public class APIParams { public String name; public String category; public Boolean taxable = false; } Then I have a ...
0
votes
1answer
15 views

How can I write a unit test which includes ApexPages.StandardController methods?

Currently looking at the Using Dynamic References with Custom Objects and Packages tutorial. For reasons I won't speculate on, step 7 included the controller extension code (again) instead of the ...
0
votes
1answer
19 views

Unit Testing Help

I've been reading up on Unit testing and I'm trying to get a test done for a class. I want to delpoy this to our live Org but am pretty stuck at this: The Code itself works but I've never done unit ...
3
votes
1answer
52 views

How can I test create an instance of a VisualForce Controller Extension for testing?

Typical of custom controller extensions, my extension has a signature public MyVFCtrlExt (ApexPages.StandardController standardController) I'm currently trying to figure out how to write unit tests ...
1
vote
1answer
24 views

Unit Test for Report

I need to write unit tests to call a method that validates the content of a Reports.ReportResultsObject. Is there a way to create reports programmatically, execute them and use the ...
3
votes
1answer
15 views

SiteAuth UserAgent Test Class Creation

I'm new in creating SiteAuth userAgent test class creation. public SiteAuthControl() { if(!Test.isRunningTest()) { string userAgent = ...
2
votes
1answer
48 views

Unit tests executed via metadata API failing on call to system.test.startTest

I have an CI system using Jenkins and the metadata API to automatically execute all unit tests in our packaging org. Some, but not all, of the unit tests have started failing at the point where the ...
3
votes
2answers
93 views

Test class for trigger on custom object

I just wrote this trigger and it seems to be working fine in dev, I need to move it into production, however, the test class I wrote passes the test but does not cover the trigger. Any help would be ...
1
vote
2answers
29 views

Best Way to Assert a Bulk Insert

I've done some searching and having trouble finding an answer to what I'm assuming is a bit of a noobish question. I'm writing a test class for code which updates the owner of a lead. I'd like to ...
4
votes
1answer
23 views

Best practices for naming unit tests [duplicate]

My organization has a mishmash of apex classes, both regular classes that execute specific business logic and test classes that execute unit tests on those regular classes. When we started developing ...
0
votes
1answer
41 views

Test Class Coverage Issues with Inner Class - Need assistance to increase code coverage

I am currently having an issue with test coverage for an inner class and need assistance. I am not sure how to get past the validation method that is being executed within the save method. The ...
1
vote
1answer
35 views

De-Reference a Null Object

I'm a new admin in an org that has had some custom development done in the past and our code coverage has fallen below 75%. In one of our Apex Test Classes, we get an error that states: ...
1
vote
1answer
147 views

Why does my delete trigger cause a 'Too Many SOQL Queries' error?

I have a trigger that is supposed to see if a field is empty and, if it is empty, it is supposed to check if there is an Account Team Member with a certain role. If that is true then it is supposed to ...
0
votes
1answer
36 views

How do I use system.assert, system.assertequals, system.run as in my unit test?

I am new to Salesforce. I wrote test class for below program, but it is simple. I want to make use of system.assert(), system.assertequals() and system.runas() commands methods for the below test ...
0
votes
1answer
17 views

Why do i get this Error :Error: Compile Error: unexpected token: '}' at line 27 column 0

Can any one help out in this test class. Why do i get an Error as : Error: Compile Error: unexpected token: '}' at line 27 column 0. The test class written is right or do i'm making any mistake? ...
2
votes
1answer
19 views

Test custom controller that does not use parameters directly

Given a custom controller that uses a record selected by a standard controller (not through id parameter), how can I ensure that the appropriate Custom_Field__c field is available in the unit test? ...
0
votes
3answers
35 views

How many Test classes should be written?

Can any one help me out .Based on my requirement i have written two triggers , one on case object and one on Case comment.1)Now how many Test Classes should i write now .2)I have written a test class ...
2
votes
1answer
27 views

Test Execution Slowness [duplicate]

Anyone else experience a major slowdown in test execution? I have approximately 300 test methods that I run daily. What used to take 40-60 minutes now takes 2-3 hours, and the slowness is also ...
0
votes
1answer
25 views

Code Coverage is None for Test Class

Can any one help me out .I shall appreciate your help. I have a two triggers running on my Requirement as 1) Create a case with Subject line (User ) ----First Case 2) Create another case with Same ...
0
votes
1answer
22 views

How to set closeDate of a Case record in the test Method?

I am writting a test method, where I have to set closedate of a case record to an old date. I know, i can make Status to "closed", but it will give you close date as Today. Is there any other way, ...
0
votes
0answers
26 views

Is there a way to test Triggers with mocks?

When I write triggers, I try to follow best practices by implementing them according to the Separation of Concerns principle. This design pattern allows me to encapsulate logic and separate it from my ...
-5
votes
1answer
25 views

How do we increase the size of a pdf file in salesforce while generating in pdf format?

find below screen shot , i created 22 fields ,only its showing 16 fields are missing please let me know if any suggestion in this scenario ?
1
vote
1answer
45 views

If I create a user in a testmethod, I cannot select them with SOQL in the same testmethod. How can I work around this?

I am creating a test method to test functionality allowing users to search for other users. In order to do this, I have tried creating and saving test users with certain criteria, and then searching ...
-1
votes
0answers
20 views

Test Class for Apex Class [duplicate]

Can Any one help me out how to write a Test Class for the Below Apex Class. I'm New to Salesforce .Any help is very much Appreciated. APS_Account_CreateCase_Helper public without sharing class ...
0
votes
1answer
25 views

Is there a way to initialize a custom setting in a test class?

My test class inserts test quote line items which sets off a trigger, that calls a Util class to pull a query of qli fields, 5 of which have their names stored in custom settings (I'm not 100% why ...
0
votes
1answer
26 views

page reference code coverage

suggest me how to cover page reference in test class. public PageReference selectedPricingReq(){ system.debug('-----> acceptedPRID: '+acceptedPRID); Pricing_Request__c prcReqObj = ...
1
vote
2answers
92 views

How do I test an apex trigger that sends an email

Trigger is: trigger emailtemplate on opportunity(after update) { List<opportunity> oList = Trigger.new; List<opportunity> nList = trigger.old; ...
0
votes
0answers
18 views

code coverage considering comments and debug statements

(Please dont mark it as duplicate).For one of my class, comments and debug statements are getting considered for code coverage. I cleared the test data/results but then also the comments and debug ...
11
votes
2answers
63 views

Test.loadData() - undocumented behavior

Premise I want to load Accounts and their related Contacts using Test.loadData() and StaticResources. How do I do this given that the Contact records must have the ID of their parent Account yet the ...
4
votes
2answers
49 views

How to generate a random string value based on regex pattern

I'm trying to build a random external ID generator that can take a complex pattern described in RegEx and generate any number of unique strings for unit tests. Ideally something like Xeger which ...
1
vote
4answers
48 views

MIXED_DML_EXCEPTION when creating PermissionSetAssignment in test class

I keep getting following exception when trying to assign permission set to a user in test class: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML ...
2
votes
1answer
25 views

JSON.createGenerator(true)

I am creating a JSON generator that returns the created object to be parsed in a different method. However when I am creating a field using the writeStringField method of JSON with a value of null, it ...
0
votes
1answer
76 views

Mock Unit Test for a REST API callout

After attending DF14 I have a fairly solid understanding of the HttpCalloutMock() when unit testing for REST callouts, but I'm having trouble implementing unit testing for the first time. The ...
6
votes
2answers
60 views

Best Design for an easily maintained Unit Test?

I'm attempting to design a Unit Test Utility that we can use across our 15++ UE Orgs. I'm aiming to accomplish the following goals: Reads from a declaratively-maintained map of required field/values ...
4
votes
1answer
169 views

How is the Test Code coverage required for deploying calculated?

Would like to Know- suppose we've sandbox from which we deploy to production. There is already set (A) of classes, some of whose test classes are failing Now we want to deploy Different set(B) of ...
5
votes
2answers
88 views

Test Class SeeAllData=true Annotation

I am creating a test class that will test my controller class which uses almost 5 to 8 objects that has many DML statements like insert and delete, however I am feeling a little bit worried about not ...
2
votes
1answer
23 views

Constructor not defined error when deploying to production

i'm getting a bit lost in the weeds with the error I'm getting when trying to deploy this simple test class to production. In the sandbox, it compiles fine and runs fine test-wise, but when it comes ...
0
votes
1answer
58 views

Please help me with below test coverage

I have below trigger. And i have one test class. Trigger is Covered 76%. i want to make it more than 90%. The code which is not covered is at line numbers : For Trigger 1 :14,17,25,26,27,32 For ...
3
votes
1answer
24 views

Tool for check valid test cases in Salesforce?

We have a existing project which has a number of invalid test cases - which means, test cases only have the code coverage but don't have system.assert in it. I remember there is a tool to find those ...
0
votes
2answers
41 views

Increase test coverage for query IsSandbox =true

I am checking for sandbox with help of query select Id from Organization where IsSandbox =true limit 1 but now in production and developer org my code coverage is going down to 33% as this query is ...
1
vote
4answers
50 views

Unit test for trigger SOQL query that is uncovered

I'm having an issue finishing up my unit test, and I think it is related to the SOQL query in my trigger. The trigger itself checks to see, upon Lead creation, if a Contact exists with a matching ...
0
votes
1answer
15 views

Test Class to cover NotesandAttachment

I am creating one test class to cover this query.The query is covered, I tested one value retrieved but it does not go into for(NoteAndAttachment h:actOpen.NotesAndAttachments) loop. List< ...
2
votes
0answers
51 views

No test coverage on after insert trigger

I can't quite tell why code coverage is saying that there are 0 lines covered. My objective is that every time an Award is inserted, an Award Judging Criterion is inserted with a link to the Award. ...
1
vote
3answers
118 views

Problem with System.assertequals in test class code

I have below trigger code : trigger updateopportunities on Account(after update) { Set<Id> accountIds = new Set<Id>(); for(Account ac : Trigger.new) { ...
2
votes
1answer
44 views

Cannot use @istest in Apex Triggers

I'm brand new to Apex/Salesforce development, and am attempting to create some Apex triggers and tests. Each time I try to add a new class, when I start it with @IsTest I am unable to save it. I see ...
1
vote
1answer
32 views

Help Creating a Test Class for a VF Controller

Apex newbie here and would really appreciate the help on a test class I'm trying to write. Basically, a VF page called "Invoice" is getting created when a button is pressed on the Quote object. The ...
2
votes
2answers
123 views

Test class Standard price book entry error STANDARD_PRICE_NOT_DEFINED

i got error in my test class. System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: [] my test ...
0
votes
0answers
43 views

System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped

we have written trigger for echo-sign object, after updating object through our trigger, echo-sign code calls @future method from their managed package. this future method has webservice callout. Our ...
0
votes
3answers
107 views

Apex test 3% code coverage,

Need Help! I have a test class GoogleMap_Meeting_Controller_Tester with 3 objects, location(master), groups(child) and meeting(grand child). The SOQL query is returning a rowthe Apex coverage is still ...
-3
votes
2answers
62 views

Help with Code coverage, Loop and if conditions

I'm unable to have code coverage. Wrote a test class that has 24% coverage. How should I test loops and conditional statements? Following is my Apex Class... public class OrderTrackingList{ ...