Questions tagged [code-coverage]

Questions about specific lines of code that need coverage or platform bugs. 75% of your Apex code must be covered by test classes. This tag is not intended for use when code coverage is simply lacking, but for scenarios where because of a particular configuration or system issue code coverage is challenging.

Filter by
Sorted by
Tagged with
0 votes
1 answer
49 views

Schema.sObjectType.(...).isUpdateable() method is returning true but should return false

In short, I'm trying to follow the PMD Source Code Analyzer Project, and I realized that before making an update I must validate whether the user has permission to change the field (ApexCRUDViolation)....
Noops's user avatar
  • 3
0 votes
1 answer
33 views

Test Class Data for PlatformEventUsageMetric

I have a simple, invocable class to query delivered platform events using the PlatformEventUsageMetric object and it is working in flow, but I'm not sure how to create a test class for it if I can't ...
Kendra Broom's user avatar
3 votes
0 answers
73 views

Platform Event triggers for Subscription Management events cannot be covered by unit tests

As part of the Subscription Management license, certain platform events are fired when an Asset is updated, an Invoice is processed etc. For example the CreateAssetOrderEvent. Currently we are using ...
shooting at the moon's user avatar
1 vote
0 answers
38 views

Manually loading apex test code coverage from sfdx command into vsCode

Whenever I run tests through vsCode, the tests take very long time to complete (a single test could take up >10 min or they time out with the "Your request exceeded the time limit for ...
Luis M Valenzuela's user avatar
-1 votes
0 answers
20 views

Can someone help in creating test class for this apex batch code? [duplicate]

global with sharing class DC_DripBulkAndJeopardyBatch implements Database.Batchable<sObject>, Database.Stateful,Schedulable{ //Static Status that is considered in Jeopardy and Drip Bulk. ...
Andrew Willie's user avatar
1 vote
1 answer
54 views

Test Coverage issue for a simple rest-service class

Just get started with Trailhead but got stuck with one challenge. It requires you to write an apex class to implement a REST GET service to retrieve an account and associated contacts. Then you have ...
user9035826's user avatar
0 votes
1 answer
53 views

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

I wanted to write test class for Triger which insert contact on user Insertion. So I am writing test class to check whether new created contact is related to that user or not but Im receiving error. ...
Sajid's user avatar
  • 13
0 votes
0 answers
55 views

Partial mocking using ApexMocks Framework

I want to perform partial mocking using the Salesforce FFLib ApexMocks framework. For example, I have a class like the one below: public class PropertiesServiceImpl implements IPropertiesService { ...
Seleukos2's user avatar
-1 votes
1 answer
31 views

Help with StandardSetController Test with redirect

I have a visualforce page that grabs the ids from a list view of the selected records. Then redirects to lightning component. I'm having trouble with my test class. I'm not able to get the assertions ...
Jeff Bieber's user avatar
-1 votes
2 answers
68 views

How to do code coverage for Trigger/create a test class and trigger handler for trigger [duplicate]

First, I am totally new to Apex Trigger, I'm still learning the Apex Class and Triggers. I just found a code that actually works in our org. So what it does are below. get the record type id and ...
Paul Grael's user avatar
-3 votes
1 answer
50 views

Apex test class not working and fails

I have the following apex class: public with sharing class TT_DisplayRelatedOpportunities { @AuraEnabled(cacheable=true) public static List<Opportunity> getOppList(String recordId) {...
Marjan's user avatar
  • 15
0 votes
2 answers
47 views

Cannot Increase Code Coverage for Salesforce supplied Lead Conversion Apex Class

I am trying to utilize this Apex Class supplied by Salesforce but when i try to deploy to production i get a code coverage of 68%: global class ConvertLeadAction { @InvocableMethod(label='Convert ...
Zack Gibson's user avatar
0 votes
1 answer
33 views

MIXED_DML_OPERATION, DML operation on setup object

My Apex Class public with sharing class WeekendTimeSheetAlerts implements Database.Batchable<sObject>{ final String weekToSubmit; final String query; final Date weekMondayDate; ...
YETURU CHENCHU's user avatar
0 votes
0 answers
39 views

Need help on my first Test Apex class [duplicate]

I have written an Apex class which works well in dev environment, but I am having a tough time writing a test class that will give me more then 59% coverage. I tried using snippets from this and other ...
Sergio's user avatar
  • 1
-2 votes
1 answer
27 views

I want to cover catch block of this method but unable to as it is related to querying User profile. Please help

I want to cover catch block of getUserProfile method. I am providing the whole code, only catch block of getUserProfile method is not getting covered. TestClass @IsTest private class ...
SF Learner's user avatar
1 vote
1 answer
104 views

How to write an APEX Test Class with Multiple Http Callouts (Renamed)

I'm relatively new to programming, and I am attempting to write the Test Class for an Apex Class that has an HTTP Callout. I have already created the HTTP Mock Class to simulate the Callout, but when ...
nigeldendy's user avatar
0 votes
1 answer
46 views

I want to cover catch block of main class to have 100% code coverage. Can't seem to throw exception. If anyone can help

I am able to cover try block of my main class, but failing to do the same for catch block. Here's the given code for my current test class and Main Class. Controller Class- public with sharing class ...
SF Learner's user avatar
-1 votes
1 answer
24 views

its not covering in my test class can you please anybody help me on this,

obj = SAPIntegrationToGetMAP_SL__c.getInstance('Integration Details'); if(obj !=null){ username = obj.Client_Id__c; password = obj.Client_Secret__c; } for this have written like this @...
sams's user avatar
  • 1
0 votes
1 answer
36 views

Test Class for multiple external objects

I am trying to write a test class for a apex class that contains multiple external objects. I`ve tried the answer in this link. Although test is passed, the code coverage is only 37%. How can I ...
ibrahimaslan's user avatar
0 votes
1 answer
86 views

How to write test class for generic method to get picklist options

I need to write test class for this method involving the generic method to retrieve Picklist options: @AuraEnabled public static Map<String,String> retrievePicklistOptions(String objApiName, ...
Makc M's user avatar
  • 25
0 votes
0 answers
51 views

schedulable class shows 0% coverage while trying to deploy to Production

I have a Schedulable class which calls a Batch class, I have enough coverage when checking in sandbox, But when trying to deploy to production Scheduler class shows 0% and Batch class shows 60%. I am ...
sangeetha balasubramanian's user avatar
1 vote
1 answer
86 views

Code Coverage requirements for External Services and Flows in Unlocked Packages

I created an unlocked Salesforce package that contains an External Service and an Inactive Autolaunched Flow that calls methods in the External Service. The package does not contain any Apex classes ...
Mary Hamlin's user avatar
0 votes
1 answer
35 views

Will you please tell me how to get test coverage for finish method were sending error mails in this batch class [duplicate]

public class MyBatchable implements Database.Batchable<SObject>, Database.Stateful { Exception[] errors = new Exception[0]; public Iterable<SObject> start(...) { ... } ...
M S's user avatar
  • 3
-5 votes
2 answers
77 views

System.NullPointerException: Attempt to de-reference a null object on test class

I have getting error as System.NullPointerException: Attempt to de-reference a null object on the test class Class:- /* * @Class Description- Contact Trigger Helper. * Class is introduced to handle ...
user68781's user avatar
0 votes
1 answer
53 views

Issue : "No content to map to Object due to end of input" in test classes

I am getting Issue in test class. I am not able to cover the test coverage of responsebody When I debug it show the "common.apex.runtime.impl.ExecutionException: No content to map to Object due ...
Abhi's user avatar
  • 1
0 votes
1 answer
352 views

AssertEquals not working as expected

I have a test class that works on my org dev, I'm trying to make deploy in another org but it's having a strange behavior, the error is in the first assertEqual: @isTest static void testUserStore()...
Alexia's user avatar
  • 73
0 votes
1 answer
71 views

IF ELSE STATEMENT IN Classic email template

Can I add a condition to add number of terms (number field) to the installment date (date field) in Classic Email Template. Example: Number of terms is 30 and Installment Date is 3/01/2023 in the ...
Danica Alexis Llantos's user avatar
0 votes
0 answers
38 views

Apex Failed Test Run: Method does not exist or incorrect signature

I have a class with the function: public static void updateTargetAmount(Id targetId, String customFieldApiName){...} In my Testclass i handover the 2 parameters: TargetHelper.updateTargetAmount(...
Benjamin's user avatar
0 votes
0 answers
38 views

Unable to create Feeditem for External Chatter User in test class

I am trying to create FeedItems on a CollaborationGroup as an external chatter user. Although the Group is public and Person is external user with Customer Community Plus Login license. An error is ...
AmanSharma's user avatar
0 votes
1 answer
112 views

Viewing apex code completion details after sf deploy fails

I'm writing an Apex trigger and testing it against a Salesforce developer instance. I've been writing the code in VS Code, and deploying by running sf deploy. When I run sf deploy the Test results ...
David Kane's user avatar
0 votes
0 answers
21 views

i am getting 60% code coverage for this class . how to increase [duplicate]

public with sharing class DashboardSharing { private static final Integer METADATA_API_VERSION = Integer.valueOf(new MetadataService.MetadataPort().endpoint_x.substringAfterLast('/')); public List<...
niranjan vl's user avatar
-1 votes
1 answer
203 views

how can you increase code coverage without modifying test class? [duplicate]

If class has 74.5 % coverage then how can we increase 0.5% coverage without modifying test class?
Jarvis's user avatar
  • 1
0 votes
0 answers
65 views

Apex Test coverage for impersonation or login as user

Is it possible to write a test class to mimic the impersonation ? Due to one of the salesforce release, impersonation has failed and salesforce support mentioned that the issue should have been caught ...
Hemant-2's user avatar
0 votes
0 answers
56 views

How do i create test record for Product Media Object?

I've written a function that accepts a product id and returns the product Media record associated with that Id. I need to test that method, but I can't create a Product Media record in the test setup ...
Siddharth Verma's user avatar
0 votes
1 answer
66 views

MileStoneUtils apex class requires code coverage. Stops at 57% [duplicate]

Working off of the code provided here https://help.salesforce.com/s/articleView?id=sf.entitlements_milestones_trigger.htm&type=5 The test class does not cover required coverage specially the if ...
Abhinandana 's user avatar
0 votes
0 answers
31 views

for loop in a test class [duplicate]

I've been struggling with covering a for loop in the below test class on line 40. I have attached both test class and original class Original Class public class CapEventsToPropertyDistanceCalculator { ...
Yongama Dayeni's user avatar
0 votes
2 answers
205 views

Test class coverage required for Custom metadata that turns a Trigger on and Off

can some one tell me how to cover custom metadata in test class? in particular if (Trigger_Disabler__mdt.getInstance('Account_Disabler')?.Disable_Trigger__c == true) line in the code below. Context ...
Abhinandana 's user avatar
0 votes
0 answers
13 views

My apex class not covered [duplicate]

I need your help to know what´s happend witc my test please. I have my apex class called "CCS_InterfazCargueFactura_cls" and my test "CCS_InterfazCargueFactura_tst" but I don´t ...
Jeffer Monroy Melo's user avatar
-2 votes
1 answer
52 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, ...
Guest's user avatar
  • 3
0 votes
2 answers
290 views

How to cover try and catch block in test apex class

How to write test conditions for try and catch blocks in apex. My code coverage is not 100% by below code. Please help. Apex class: public static List<String> getUserName(List<String> ...
user115525's user avatar
0 votes
1 answer
64 views

I need some help to deploy apex class that is for a visualforce page from Sandbox to Production

this is my first time trying to create an apex class and deploy it. It is very basic and is just the back end for a visualforce page. However to deploy to production I need to make a test apex class ...
Rory Plewes's user avatar
0 votes
2 answers
151 views

Apex test class method not working

I have the following method in my apex class: @testVisible private static Custon_Object_Case__c getExistingRecord(Messaging.InboundEmail email){ List<String> referenceId = email.references; ...
Marjan's user avatar
  • 15
0 votes
0 answers
19 views

How to write Test class for below Code? I'm calling a Json file/Application in static Resource through Composite call HTTP and loading into Object [duplicate]

public class AfterSandboxRefreshed { public static void LoadRecordsCountry(){ Organization currentOrg = [SELECT Id FROM Organization]; if (currentOrg.Id != '...
Santosh's user avatar
0 votes
1 answer
36 views

How can I create test class to use the hyperlink field?

I have a custom object with formula field using hyperlink function. However I need to create a scenario in apex test class where a formula field (using HYPERLINK formula) is click. Example of a ...
user11880836's user avatar
0 votes
0 answers
90 views

How to Create a Test class with a Future Callout that is not dependent on an HTTP Response?

I am new to Apex, but I have been tasked with sending a Salesforce Custom Object to another Company system. My Class works as expected, but my test class fails due to having a @future method. I did ...
nigeldendy's user avatar
-1 votes
1 answer
167 views

Could we make Mandatory Field null in test class?

I have custom object ABC__c . i have mandatory custom field Account__c on this object which is a master detail. Can we make this fields as null in a test class?
Saurabh Kumar's user avatar
0 votes
1 answer
58 views

Asking for License to assign a permission set to a user in test class

Hi all i am assigning a permission set to a user below the code " public static void assignPermissionSetsToUser(Id userId, Set<String> permissionSets) { List<...
Vishal's user avatar
  • 1
0 votes
1 answer
371 views

How to runalltest in package.xml and deploy to org?

I have package.xml file which contains apex classes, test classess , triggers. So, I need to runalltest in the org only run test class which is contained in my manifest file and deploy to org is ...
Neetesshhr's user avatar
0 votes
0 answers
46 views

Metadata API Deployment Unit Test Results, CodeCoverageResult.dmlInfo is always null

Trying to build a report of Deployment metrics with Metadata API. The documentation says that the CodeCoverageResult object should contain performance metrics for DML, SOQL, and methods which is ...
ChefFromSpace's user avatar
-1 votes
1 answer
192 views

Assign null value to Formula Field in a test class

Hello i have custom formula field name-sau__c on custom object NEw__c. In test class i need to passs null value to this formula field . to increase coverage of my code. formula field -Sau__c is ...
Saurabh Kumar's user avatar

1
2 3 4 5
27