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)

-1
votes
0answers
23 views

Creating a unit test for a trigger

This is my first stab at creating unit tests so I am learning a lot as I go. The first block of code below is the piece that I have been focusing on creating test coverage for and below it is the ...
0
votes
0answers
6 views

Writing test cases for Salesforce sdk hybrid_local applications

I want to write test cases for my salesforce sdk hybrid_local applications. I use angular js. After some reading figured out that Jasmine, Karma(unit tests) and Protractor (end to end tests) are the ...
0
votes
2answers
24 views

Unit testing a trigger - expecting right curly bracket, found 'insert'

I am creating unit tests to test a trigger that makes a calculation with particular variables depending on the value of a different. I believe the code below is correct, however I cannot figure out ...
0
votes
1answer
31 views

Deployment error while deploying

Apex class: public void post(){ HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); req.setMethod('POST' ); ...
1
vote
1answer
32 views

Unit Testing a Trigger

Here is the piece of code for a trigger that I need to break into unit tests. I was thinking that I could begin by testing the most further in if statements as one unit test and make an additional ...
-3
votes
0answers
37 views

Test class in Account [closed]

I'm trying to create a test class for my trigger. Can someone help me with this? trigger Atualizar_Fotosfaltantes_AR_case on Account (after update) { public List<Case> casesToUpdate = new ...
4
votes
3answers
99 views

Test Apex Code: How to emulate a SOQL call that has a related object?

For Apex testing, I'm trying to create an object that is the same as the one created with a SOQL statement (see following method). The method retrieves the Quote_To_Lease__c object from Salesforce ...
-3
votes
0answers
34 views

TEST CLASS COVERAGE FOR LIST VIEW [closed]

I am getting only 23 % coverage for the given class Please suggest how can the coverage be increased. public class QueueController { public List<Group> GroupNameList{get;set;} private ...
0
votes
2answers
88 views

Help me out with Apex Test class for the Apex trigger

Can any one help me out with this Test class written for this trigger is right or wrong.The Test class get saved but unable to see the code coverage. Here is the Code for the TRIGGER : trigger ...
3
votes
1answer
30 views

Programmatically Create Record Type

Is it possible to programmatically create a record type in Apex to be used in a test?
0
votes
1answer
22 views

Test Class to verify fields updated the same as the expected output

I'm creating my first test class got stuck with this one could you help me verify and correct the line of code for me. //Create a new record for Address Object with Local record type ...
-1
votes
0answers
12 views

How to write apex tests for custom settings? [duplicate]

I want to write a test class for a trigger which contain a custom setting. trigger UpdateState on account (before insert,before update) { map<String, CityStateSettings__c> CityMap = ...
0
votes
1answer
22 views

variable doesn't exist

I was getting too many soql queries, so decide to split the unit test. Now i am getting the error variable doesn't exist:rtmap @isTest(SEEALLDATA=true) public class test_createCaseFromOppt { ...
2
votes
2answers
185 views

Compile Error: Method does not exist or incorrect signature: Test.startTest()

I am experiencing something weird on the Sandbox with all the test classes. whenever I run a test class I get the error: Method does not exist or incorrect signature: Test.startTest(). I am ...
2
votes
0answers
20 views

Async Callout Test Failing in Production

Situation I have implemented an API to communicate with the external system. After 18th of August test that i have on production have started failing showing the infamous: ...
11
votes
1answer
63 views

Is it possible to simulate record locks in test methods?

I would like my test cases to also test exception handling. In theory an easy way to cause an exception on DML is to lock a record that it'll update so that the update will fail. But I'm having ...
4
votes
2answers
70 views

System.QueryException: No Such Column - Strange RunAs Behavior with Summer '14?

Question Is there any known reason a SOQL Query would return a runtime System.QueryException on a custom field in test methods, in particular one one via a parent lookup in a test? I would have ...
1
vote
3answers
63 views

Is it possible to get 100% Apex code coverage all the time?

Is it possible to get 100% code coverage all the time by considering all cases such as positive/negative, bulk/single etc. Are there any cases which can't be covered by test classes? I often hear that ...
0
votes
0answers
20 views

Suggested Unit Testing Approach When Checking for XML Child Nodes

Unit testing is currently at 60% code coverage on a specific class. Many of the lines of code that aren't covered by tests look like the following: global class IFXIndividuals { global ...
5
votes
5answers
293 views

Why isn't a SOQL query of mine populating a list in an Apex test class?

Why does my taskOpp query below not return any records when I run this test? The query works fine in Workbench and my taskRT query works fine in both my code and in Workbench. public class ...
1
vote
1answer
31 views

Advice on writing basic Apex Unit Test

The purpose of the controller below is to return the value of the one__c field on the Acc_Plan__c object, and then pass it into the getIsOneTrue() method. The controller works fine, but I have to ...
1
vote
0answers
34 views

Calling a webservice method from apex test class

I have a simple webservice method that updates Account Status from a custom Button in the Opportunity page: Global class Backoffice { WebService static Integer GenerateBackofficeTask(id opId) { ...
-1
votes
0answers
21 views

Test class doesn't cover Trigger [duplicate]

Can anyone give me the test code for my apex trigger: trigger Test_Share on Test__c (after insert) { Id UserId=UserInfo.getUserId(); Boolean bln=false; List<Id> ParentUserId = new ...
0
votes
1answer
29 views

Inserting Test.loadData in into Salesforce DB for tests

I am able to load the static resource but I am unable to insert the loaded accounts into salesforce. I want to do this to be able to test various methods that depend on first selecting a particular ...
0
votes
1answer
84 views

Invalid Cross Reference Key : Record Type ID value isn't valid for User: 012v00000008f4nuBB

I am having some issues. The below is a code snipet of my test class. The class complies and produces 96% of coverage with no errors. When deploying in production it throws the above error. ...
3
votes
1answer
35 views

System.VisualforceException: Invalid value for property label: null

Sigh. So I am required to cover my Apex code with tests. I'm testing a piece of code that dynamically builds a tree of controls with a PageBlock as the root object. This code works fine when NOT ...
2
votes
1answer
28 views

Speedup Testing with Force.com IDE using slim Logs - but how to set the log-level?

A lot has been written here about slow development in general and slow testing in particular e. g.: Slow development Faster unit tests? For my use case I found one reason for slow testing while ...
-1
votes
1answer
32 views

Apex Testing - Best Practices [closed]

A general question asked from time to time on stack exchange is how to implement tests. There are some general questions to ask: What are your testing best practices? Thanks for sharing your ...
1
vote
1answer
14 views

Production Test Execution “Could not run tests on class …”

While running my test cases within my prod environment, I noticed quite a few messages as the title describes, and I don't understand why. Do you have any insight on why this is happening? It seems to ...
1
vote
1answer
106 views

Can some help me get coverage for the below trigger?

Trigger: Trigger copyEquipmentonsite on Unit_Placements_Sales__c(after insert, after update) { List<Services__c> sub=new List<Services__c>(); for(Unit_Placements_Sales__c u : ...
1
vote
1answer
47 views

Unit Tests max number of test methods in a class?

I have many unit test methods (30+) in a test class that cover my class well - setting up data, setting the page and controller, calling methods and setting properties, doing asserts. But when I look ...
1
vote
1answer
42 views

Test for sendEmail() error

Hi I have built a class and a test and I am getting close to getting the test to work. I am trying to send an email using a template. But I am getting an error on the last line of code. Save ...
0
votes
2answers
61 views

How to call action function method in the test class

How do I call a method in my test class which is basically been called from the action function on the vf page? VF page: <button type="button" onclick="myJSMethod();">my button</button> ...
0
votes
1answer
22 views

Performing an Upsert in PageReferenceSave - Not updating Item.ID for Use In UnitTest

I have a test that creates a new record in our custom table - Service Offered. Whe I call my controller and save - It creates/updates the record correctly, and in my class the Debug.Assert gives me ...
3
votes
1answer
68 views

How to mock a SOQL query in Apex

Our Apex unit (true integration) test run takes about an hour to complete (260+ individual unit tests) and this really slows down our dev process as we are trying to adhere to Continuous ...
0
votes
0answers
44 views

Insert contact statement in test class is causing 0% code coverage

I've written a simple trigger to prevent duplication of a lead based on existing leads and contacts. My test has 90% code coverage based on the tests that I've written to prevent lead duplication. ...
1
vote
1answer
53 views

How to access recordType in Test Methods with seeAllData = false

I am writting a test method for a certain code.This code is fetching Record Type detail from an Object Service_Form__c. Class: String recordTypeName; Schema.DescribeSObjectResult srfDescribe = ...
0
votes
1answer
30 views

How do I write a test class for the below trigger? [closed]

I have just created the below trigger that is deigned to create a new custom object record(Services) when a custom date field (Service_Date__c) on another custom object (Unit)is equal to "This Month". ...
3
votes
0answers
114 views

Unit Test: You have uncommitted work pending. Please commit or rollback before calling out

So I have a method that takes as a parameter an Id of a object and uses it to make an external callout. Unfortunately I can't seem to figure out any way to test it. @isTest static void ...
2
votes
2answers
37 views

Testing code where maintenance tables are involved

I suppose this is more of a general programming question than a strictly Salesforce question. I have a trigger which clones / creates new record when criteria fits the match: trigger cloneObj on ...
4
votes
2answers
96 views

Scheduling Run All Tests

is there a simple way to schedule the run of all test classes? I want to avoid having to do this manually every day. Thank you!
2
votes
1answer
37 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 ...
0
votes
2answers
32 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
103 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
60 views

Problem in System.assertEquals method [closed]

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
21 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 ...
2
votes
1answer
224 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
28 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
149 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
61 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 != ...