Linked Questions
115 questions linked to/from How do I write an Apex unit test?
1
vote
1
answer
6k
views
Test Class for Contact [duplicate]
I have a code that is testing a batch, I am creating a contact and an Account , but the contact isn't getting linked to the account (c.AccountId = null). The same code is tested in Async window and it ...
-2
votes
1
answer
3k
views
test class for apex class creating multiple object records [duplicate]
Can anyone helps me out in writing the test class for below apex class.
I know that I should not post it here asking for this kind of questions but as I am new to apex and I need to deploy so I was ...
0
votes
1
answer
3k
views
How to write test class for below Vf Page Controller [duplicate]
Class
public with sharing class CreateQuotePDFController {
public list<QuoteLineItem> quoteLineItemsList{get;set;}
public Id getid{get;set;}
public Double grandTotalTax{get;set;}
...
0
votes
1
answer
908
views
how to write Test class for generate Random String method present in a class in salesforce [duplicate]
@AuraEnabled
public static Integer generateRandomString() {
try{
return Math.round((Math.random() * (900000) + 100000));
}
catch (Exception e)
{
throw e;
}
}
1
vote
1
answer
2k
views
How to test trigger that compares Trigger.new with Trigger.old [duplicate]
I have a simple trigger that runs on Account update, and the only logic is a check to whether or now BillingPostalCode changes or not.
This is my code:
trigger ZipCodeUpdated on Account (before update)...
-3
votes
1
answer
2k
views
Test class trigger.NewMap trigger.oldMap on opportunity [duplicate]
I need to write a test class on my OpportunityTriggerHandler and I'm having some difficulties to define how to construct the logic & scenarios in my test to test and the data to build in my test ...
-2
votes
1
answer
677
views
Test Class for a simple Apex Class [duplicate]
I am trying to write a test class for a simple Apex Class which sets the status of the Case to be Closed like below
public class updateCaseRecord {
@AuraEnabled
public static void ...
-1
votes
3
answers
837
views
How to write a test class for this below code can anyone help me [duplicate]
I want to write a test class to achieve 100 % code coverage for this below code can anyone help me to solve this problem i don't know how to write a test class for using this trigger
Trigger:
trigger ...
0
votes
0
answers
868
views
Need Help with a test class to my apex class that attaches a Visualforce Page pdf to the quote [duplicate]
I found a way to write an apex class that attaches my quote which is generated by an vf page as a pdf to my quote object.
Writing the test class is even a bigger problem for me. I get to 36% coverage ...
-2
votes
1
answer
441
views
Add test method to your test class error getting, please help how to resolve [duplicate]
public with sharing class CreateQuotePDFController {
public list<QuoteLineItem> quoteLineItemsList{get;set;}
public Id getid{get;set;}
public Double grandTotalTax{get;set;}
...
0
votes
1
answer
489
views
Test Class Coverage for Apex Controller [duplicate]
I need help in writing test class for following apex class. Could anyone please suggest how to create test data,test the following method defined in apex class with positive and negative scenarios and ...
0
votes
1
answer
538
views
How to get rid of this System.ListException: List index out of bounds: 0 error in my test class [duplicate]
I am trying to create a new case with record type to cover the lines in my apex class but throwing the inbound error. please help me to cover the lines
This is the full method
public void ...
0
votes
1
answer
318
views
Use Map instead of For loop in my Apex Trigger [duplicate]
I'm new to coding and I need help in modifying the apex trigger below to the correct one. Can you also help me in creating a test class for this? Thank you so much!
trigger UpdateLadderedFields on ...
-2
votes
1
answer
538
views
How to cover the below lines of code in a test class? [duplicate]
Please help me in order to write the test class for the below lines of code:
Id objUser = UserInfo.getUserId();
UserRecordAccess objRecordAccess = [Select RecordId, HasEditAccess From UserRecordAccess ...
0
votes
1
answer
352
views
Test Class for Trigger on Event [duplicate]
I am new to Salesforce and I am writing a test class for the trigger. Can anyone tell me how to write a test class for the trigger below?
trigger QBRNewRec on Account (After insert, After Update) {
...
0
votes
0
answers
436
views
How to Write Test Class for If Condition [duplicate]
How to Write Test Class for If Condition...
This is my Trigger...
trigger TierPricingOffers on OpportunityLineItem (before Insert,before Update,before delete)
{
if(trigger.isBefore)
{
Set<...
-1
votes
2
answers
492
views
What is test class for below code? [duplicate]
public class UtilityClass {
public static String getDescribedObjects( List lstSObjectType ) {
// Globally desribe all the objects
Map<String, SObjectType> globalDescribe = Schema....
0
votes
0
answers
350
views
Test Class for Dynamic SOQL [duplicate]
Pretty new with salesforce dev. So forgive me.
I am doing a SOQL query and then updating records.
The trick here is . I am grabbing my query from two custom fields which are in the Custom Settings . ...
1
vote
0
answers
332
views
Test Class for Batch Apex Schedulable batch Process [duplicate]
I need help in writing test class for the below Apex Schedulable batch Process.
Can anyone help me out.
global class CLM_Batch_ExpireAgreements implements Database.Batchable<sObject>,...
0
votes
1
answer
244
views
Test Class with wrapper [duplicate]
I have a problema with a Class test in the wrapper class..
This is mi class and doesn't have any error:
public class ValeDeSalida_cls {
private ApexPages.StandardController sc;
public String ...
0
votes
0
answers
228
views
Apex Test Class is Failing - (System.QueryException: List has no rows for assignment to SObject) [duplicate]
I am brand new to coding and this is my first test class. I have spent hours trying to get it to pass.
Apex Trigger That I am Testing
trigger RenameTransaction on Financial_Transaction__c (before ...
0
votes
0
answers
242
views
Please I need help writing a test class for this scheduled class [duplicate]
public with sharing class Repeating_Scheduler implements Schedulable{
private final String JOB_NAME = 'PriceBookEntryHandler Job';
private final Integer ONE_MINUTE = 1;
private void ...
0
votes
0
answers
233
views
Creating an Apex Test Class for Apex class that handles a webhook integration when an opportunity in Salesforce moves to the 'Closed Won' stage [duplicate]
How can I create a test class on the below trigger?
public class webhookOpportunityStageNameClosedWon {
// call method 'handleOpportunityStageNameClosedWon' in the '...
-3
votes
1
answer
136
views
Test class not sure how to write for this code [duplicate]
I have written following apex class:
public with sharing class Persmissionset
{
@AuraEnabled
public static PermissionPagerWrapper fetchPermission(Decimal pageNumber ,Integer recordToDisply) {
...
0
votes
1
answer
267
views
How to make Test class for an invocable Lead Convert class [duplicate]
I'm trying to convert a lead by using Apex within Flow. I have this code, that I've found online for doing so. I just can't seem to figure out how to make a test class for it so that I can deploy it ...
-1
votes
1
answer
93
views
How to write Test class for the below [duplicate]
Apex class:
public class ProdImedComAr {
public class Respuesta {
public Integer Codigo;
public String Descripcion;
public Long NroOperacion;
public String ...
0
votes
0
answers
150
views
Writing test Class - Code Coverage 0% [duplicate]
Working on creating a test class for my class in my sandbox and I am receiving a code coverage 0% in the dev console.
The console isn't highlightning the lines that need to be covered in red either.
...
-3
votes
1
answer
93
views
Code Coverage for IF statement [duplicate]
May I know how I can create a code coverage for if statement code? Here is my if statement code:
@AuraEnabled
public static void submitFinalApproval(Id recordId) {
//1. RS
if(...
0
votes
0
answers
145
views
Creating a Test Class for 2 Classes [duplicate]
In order for Territory Assignment rules to fire on Account creation and Update, I have got 2 Classes working (with Triggers), however I am struggling to create a Test class for these, any help would ...
0
votes
0
answers
130
views
Test class for RequestData class [duplicate]
@HttpPost
global static List<HHSurvey> getHHSurveyList() {
RestRequest req = RestContext.request;
RequestData mRequestData = (RequestData)JSON.deserialize(req.requestBody.toString()...
-2
votes
1
answer
120
views
Test Case for custom object [duplicate]
How to write test case for below method
Custom Object : SAM_Request__c
Global Variable :crossChargeInfoSetFlag , samAdminFlag , samTeamFlag
boolean crossChargeInfoSetFlagMethod(SAM_Request__c ...
0
votes
0
answers
123
views
Create test class to achieve 75% code coverage needed for a Apex Trigger and Class [duplicate]
I wish to update a field from one custom object (Career Path) to another object (Contact details) based on whether a checkbox (Current) is true.
Essentially, it updates the Contacts details with the ...
0
votes
0
answers
113
views
Getting Apex test class to 75% [duplicate]
I am migrating and Apex Visualforce page and controller from a Sandbox to Production for the first time. The page is an update of a community registration with a few minor changes (removing a field, ...
0
votes
1
answer
108
views
Writing Test Classes in Apex [duplicate]
Is there any link (eg: w3schools) where one can practice writing the test classes in Apex ?
I am new to Salesforce and hence having confusion in writing the test classes in Apex.
-2
votes
1
answer
79
views
Can you please provide test class for this [duplicate]
global class LastLoginEmailJObs implements Schedulable {
global void execute(SchedulableContext SC) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging....
-2
votes
1
answer
55
views
How to write test class for this? [duplicate]
public with sharing class ToggleController {
@AuraEnabled(cacheable=true)
public static List< Contact > fetchContact (Id accId, String status) {
return [SELECT Status_c, ...
0
votes
0
answers
67
views
Test class - code coverage help [duplicate]
I need help on test class, this is my class:
When creating a task of type (Phone Call or Last Face to Face) then update the account fields
I have a trigger:
trigger TaskTrigger on Task (after ...
0
votes
1
answer
50
views
Developing A Test Class [duplicate]
I've written Apex classes but this is my first time written a test class. I've read a number of sources and watch videos but I don't grasp the foundation to get a test to successfully cover my code.
...
-1
votes
1
answer
57
views
I'm a novice developer, please help with writing a test class for this code.Thanks [duplicate]
global class converterSchedule implements Schedulable {
global void execute(SchedulableContext ctx) {
List<Exchange_rate__c> exchange = [SELECT Date__c, GBP__c, USD__c, EUR__c, ...
0
votes
0
answers
58
views
How do I write test class for the below code? [duplicate]
I am new to Salesforce and I was playing around. So I have a vf page in which I am displaying a modal and closing it once its done. The functionality is working well. I'm just stuck at how to write a ...
0
votes
0
answers
48
views
Write a Test for extension HELP [duplicate]
Hi Im new working with apexcode and I Crate a Class in sanbox, but when I try to upload to production it says that my coverage code is 73%
this is my code
public with sharing class ...
0
votes
0
answers
48
views
UNIT TEST TRIGGER - Coverage Test Trigger and using System.assertEquals [duplicate]
Hello, I'm new to salesforce and I have a problem with test coverage and System.assertEquals
My coverage is insufficient
And I get this as an error:
Errors :
System.AssertException: Assertion ...
0
votes
0
answers
45
views
Apex Test Class for SOQL [duplicate]
I'm having trouble providing code coverage for my Apex Class.
Apex Class
public class CSMetricsDashboardController {
public CS_Metrics_Dashboard__c dashboard {get;set;}
public ...
0
votes
0
answers
45
views
Help me build a test class [duplicate]
Hi I am new in Apex Programming, can you help me build a test class for the following code. Thanks.
public static void caseClose(Map<Id, SObject> newMap, Map<Id, SObject> oldMap){
...
0
votes
0
answers
45
views
Apex triggers and Apex test class [duplicate]
I have built this trigger:
trigger OpportunityTrigger on Opportunity (before insert) {
List<Opportunity> lstOpportunity = (List<Opportunity>) Trigger.new;
if(lstOpportunity.get(0)...
-2
votes
1
answer
35
views
in test class should pass lastweek is not equal to currentweek [duplicate]
Main class
global with sharing class FCSTWeeklyCopyBatchCtl implements DataBase.Batchable<sObject>
{
public Date todaysDate;
public String dayOfWeek;
public Date mstartDate;
...
-1
votes
1
answer
44
views
How to write test for this trigger [duplicate]
Want to write Test case and unit test for this trigger
trigger Autoleadconversion on Lead (after insert, after update) {
for (Lead lead : Trigger.new) {
if (lead.isConverted ==...
0
votes
0
answers
43
views
COVER IF CONDITIONS [duplicate]
I have an apex class and a Test class already created.
Now have added few IF CONDITIONS in my apex class, but I am unable to cover those in my TEST CLASS.
APEX CLASS:
global with sharing class ...
0
votes
0
answers
42
views
How do I write a test for my Trigger? [duplicate]
I'm currently in the test phase of my project. I suppose to write a test on my triggers if someone has the good syntax for that (I've tried but it didn't work): here my triggers
1/
trigger ...
0
votes
0
answers
39
views
Hi, Iam new to salesforce, cant able to write test class for below code [duplicate]
public class countthecontacts {
public void insertcontact(){
list<Account> acclist = new list<Account>();
list<contact> conlist = new list<contact>();
...