Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [unit-test]

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 ...

0
votes
1answer
16 views

Test class for Opportunity whose Stagename is changed to close Won/ close lost, its close date should be today, is this correct?

@isTest public class populateOpportunityTest { @isTest public static void testopportunity() { List<Opportunity> oppList= new List<Opportunity>(); for(Integer i=...
0
votes
0answers
13 views

How to add Predefined Case Teams to Case in Apex Test Class?

I am trying to add a predefined Case Team member to a Case with the following code: CaseTeamTemplate ctt = [Select Id from CaseTeamTemplate where Name = 'Some Name' LIMIT 1] caseteamtemplaterecord ...
-1
votes
2answers
23 views

i want to create batch process for project that if 2 task are at risk status project stage should at risk value

global class mybatch implements Database.Batchable <sObject> { global database.QueryLocator start(databatchableContext bc){ return Database.getQueryLocator([select id,status__c,(...
0
votes
1answer
22 views

How to catch update exception and what kind of notification to do here?

I have a trigger with helper class and test. But I don't know how to test update there and what kind of notification I need. Thanks for any help. Trigger: trigger ArchivedTrigger on Item__c (after ...
-3
votes
0answers
30 views

Please help me to cover the test class for siteRegistration controller

Need to cover the remaining lines of code.. Controller and test class... /** * An apex class that creates a portal user */ public class SiteRegisterController { // PORTAL_ACCOUNT_ID is the ...
-2
votes
0answers
22 views

trigger to update case before insert, update based on domain

I am trying to create a trigger that will automatically update contact on case depending on certain criteria. Let me explain more. I have cases that come from different domains and because of that i ...
1
vote
1answer
32 views

Can't access related record in test

I have a visualforce page which is displaying a list of opportunities. The page is working as expected - no problems. The problem is that when testing I can't access the account which is ...
0
votes
2answers
26 views

Code Coverage low even though I'm calling the method

I am coding an Apex Test Class for an Apex Class. I am have trouble understanding why some lines of code are being covered while others are not. I also don't understand why the if statement in my ...
2
votes
3answers
25 views

How do I pass record IDs from testSetup to isTest methods?

I want to create data in a test class that can be used by multiple test methods. However, for the test method to be able to access that test data, I need a way to pass the record IDs to from the @...
-1
votes
0answers
29 views

How to create Apex test class for my trigger [on hold]

I know nothing about programming and I have an Apex trigger. I can't get coverage using the basic company test class. I am guessing I need a different test class, one specifically for this Apex ...
5
votes
2answers
180 views

Is this test for callout wrong? How to make a bulk?

I wrote mock and test for callout, but I don't think it's right. I think I check wrong things with asserts and maybe call the same methods a few times, while have another ways to get 100%. Have I? I ...
0
votes
1answer
20 views

Malformed JSON: Expected '[': wrong test, callout or mock?

I have System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set and I don't know how to fix it. Callout: public class Callout { public List<Tool__c> toolsList; public ...
-4
votes
0answers
27 views

Test Class Code coverage increase [closed]

I created an test class which is 70%. How can I increase code coverage. Suggestion please. It is custom visualforce page invoke from custom button url. url passes parent id and other information too. ...
-4
votes
0answers
23 views

How to write test class for my controller? I covered only 76% I need 100% code coverage [closed]

public class AccountContactcontroller_AC { public list<Account> acclist{get;set;} public Account accountdetail{get;set;} public string aid {get;set;} //account id public ...
1
vote
1answer
41 views

Batch Test Class works in Production, Fails in Test

I've started a new job and the test code coverage here is poor. I am working to improve this and one of the batch classes has coverage of 77% in production. This is now below the org % so I thought I'...
-2
votes
1answer
22 views

when i test my trigger the error will shows Given below

Everyone When I test my trigger class the error will shows Given below System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are ...
0
votes
2answers
28 views

Running an APEX class in Production, how to add isTest to APEX code

I'm trying to learn about apex test classes, I have attached the below code. I can't execute this in production developer console, but works fine on my sandbox. I was asked to write a @isTest, is this ...
-2
votes
1answer
34 views

Cover execute method of a Batch class

first of all thank you for your time, i need some help to cover this batch class, right now the test class i will post bellow only covers the finish method and the get; set; . CLASS: global class ...
0
votes
1answer
58 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY in test class

In this test class: Using System.RunAs user in test class.But It causes below exception System.DmlException: Insert failed. First exception on row 0; first error: ...
0
votes
1answer
17 views

Test Class for Visualforce Controller Test Class Coverage

I have a simple Visualforce page with a simple controller as follows public class EDU_CustomController_Getter { private String sortOrder = 'LastName'; //This is the getter method used to parse ...
2
votes
1answer
37 views

Need help to cover {get; set;} methods on a TestClass

i need some help on a TestClass as i said above, bellow i wil show you what the class looks like and the TestClass: APEX CLASS: public with sharing class DirectDebitController { public class ...
-2
votes
1answer
69 views

Problem In covering Account Team Member

Followed Approaches: Approach1: I have created test users and Tried it,but still account team member isnot covering Approach2: If I tried for currently Logged in user below issue is present ...
1
vote
1answer
57 views

How to unit test with OpportunityLineItemSchedule objects?

I wrote a OpportunityLineItem trigger that works with the OpportunityLineItemSchedule items related to it. Now I want to write unit tests for this trigger, and want to use sfdx to push the code to a ...
0
votes
1answer
34 views

Cross object values are accessed as Null values in Test class

I have 3 objects ObjA, ObjB, ObjC - these three objects have relation like ObjA > ObjB > ObjC ObjB have a lookup field for ObjA ObjC have a lookup field of ObjB Created on validation rule in object ...
-1
votes
1answer
19 views

Test Class failing due to Mixed DML Operation Error on User

Error :- System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (...
-1
votes
0answers
19 views

Coverage for callout method class

Im trying to get the coverage for callout method class.. my testclass seems working but when I check the callout method, it only cover 63%.. for the 1st process, I want to get the "count" data from ...
-1
votes
0answers
26 views

Test class for transaction security policy to block logins by country

I have created a transaction security policy that will allow logins originating only from the US. I have written a test class for below code but it's throwing this error "Cannot Insert into ...
1
vote
1answer
52 views

Authoring a Negative Test Class for a Calculator Class

I seem to be stuck on this trailhead section on writing negative test classes. I have the class authored as follows but as this doesn't seem to reference an sObject, I am wondering what steps to take ...
-2
votes
0answers
24 views

Need help how to create test class for webservice method

How to get the coverage for webservice method? I tried to create test class just like normal class method but getting error "Methods defined as TestMethod do not support Web service callouts".. I ...
1
vote
0answers
24 views

Is there a Salesforce formula playground website / service / tool

I'm interested in using a Salesforce formula playground similar to: JS Bin - JavaScript Debugger JS Fiddle I've had a Google and cannot find anything. Does anyone know of a tool/website/service ...
0
votes
2answers
26 views

Execution AfterInsert caused by: System.FinalException: Record is read-only:

I am creating record in energy object and have to update a field with user entered value + static value while creating and updating . trigger testews on Energy__c (after insert,after update) { ...
1
vote
1answer
22 views

How to test or replicate : System.QueryException: Non-selective query against large object type

In our org, there are 220k existing user record, Based on this previous code : public static void assignOwnerId(List<Inventory__c> invList){ List<User> userList = new List<User&...
1
vote
0answers
23 views

Salesforce Contracts - Testing on Contract term/End Date

I have a class that is looking for contracts 30 days before the end Date. My problem is i am trying to build a test for this class, and in that i'm trying to create a contract where the End Date is ...
0
votes
1answer
18 views

Apex Batch Test Class Does not seem to be executing the Execute Statement

Based on the posts I read it seems like the consensus is the test record is not being created but I believe it has enough to create. The execute part of the class never seems to fire. The actual ...
2
votes
2answers
49 views

Errors after Namespace Addition for Managed Package

I am about to create a new managed package on top of Financial Service Cloud and I noticed I get errors on my test classes after adding the namespace. I tried copying a line and run it on dev console. ...
1
vote
1answer
34 views

Insufficient Code Coverage for Batch Class

global class EmailNotificationBatch implements Database.batchable<sObject>,Schedulable,Database.Stateful { /* Getting data from the account */ global Database.QueryLocator start(...
0
votes
0answers
12 views

View Web Version Link Unclickable

We are having issues with View Web Version link. It looks fine in preview but once we send a test the link is unclickable. Has anyone else run into this issue? Is there a way to fix it? I am ...
-3
votes
1answer
48 views

how to write test class for below code [closed]

Apex Class public void run() { String currentuserid=UserInfo.getUserId(); List<Id> agentIds = new List<Id>(); for(User agent : [SELECT Id,ManagerId FROM user ...
0
votes
1answer
26 views

Test Coverage for Pattern Matcher in Apex

I have the below code in my controller Class in a Verify () function - public class SA_reCAPTCHA { private Reference__c Reference; public List<Reference__c> RefID = new List <...
-3
votes
1answer
16 views

Test class example for Push Topic [closed]

I am unable to get 95-100% test coverage for below class here is my class global class BT_Invoicing_New_Override_Crtl { public ApexPages.StandardController stdCon; public BT_Invoicing__c ...
0
votes
1answer
17 views

How to test catch-part of the method? [duplicate]

I tried to put null rows and do many another things. I can't test this catch. It writes System.QueryException: List has no rows for assignment to SObject. public List<MyObject__c> getList(){ ...
0
votes
1answer
25 views

How to fix wrong test controller's filter by status?

public void byStatus(){ //Temporary multipicklist, because my main picklist isn't multiselected: String temporary = jobAdvertisement.Temporary__c; List<String> temporaryList = new ...
0
votes
1answer
27 views

Verify that code was not executed

In a unit test class how can we verify that code didn't run or a DML statement wasn't executed because a condition wasn't met? Contrived Example (Updated): public static void DoStuff(List<Contact&...
1
vote
0answers
23 views

Using Named Credential URL in Apex Class returning null static resource in test class

I am implementing Named Credentials to replace how we do callout for a certain endpoint. One of my current test methods looks something like this: @isTest private static void test_method1() { ...
0
votes
1answer
38 views

Test class for method with API call and return type String

How do we write test method for Apex class used by Lightning component where my return type of method is String but within the method I call rest api Here is my class method: public static String ...
6
votes
2answers
43 views

Does SFDX add any way of automating the setup of business hours?

It wasn't (and I assume still isn't?) possible to programmatically set up business hours via Apex code in unit tests: Set Business Hours in Apex Test Code Creating Holidays and Business Hours in Test ...
0
votes
0answers
20 views

Can we test the pagination with logic in Apex and VF? [duplicate]

My pagination logic divided between apex class and VF tools. How can I test it? VF: <apex:page controller="OpportunitiesPaginationController" tabStyle="Opportunity"> <apex:form > <...
1
vote
1answer
32 views

Apex tests cannot be enqueued during a test ERROR

Below is the excpetion, System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Apex tests cannot be enqueued during a test. It happens ...
1
vote
1answer
23 views

How to increase code coverage for catch block

I have below Apex class (DAO class) which has a try-catch block. Same try-catch block has been used in 5 different methods. I tried sending setOpportunityId as account id or null id but still, it is ...
-2
votes
1answer
28 views

How to create ApexClass record in test class?

Here are many objects on which DML are not allowed in test class. But if our code is querying ApexClass sObject then how can we create some ApexClass records in test class to cover our code?