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 update) { JTriggerHelper triggerHelper = new TriggerHelper(); if(Trigger.isUpdate){ for(Item__c item : Trigger.new){ if(item.Status__c == ‘Old’){ triggerHelper.remove(item); } } } } … Read more

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=1;i<=5;i++) { Opportunity opp= new Opportunity(); opp.Name=’TestOpp’+i; opp.StageName=’Prospecting’; opp.closeDate= Date.today()+10; oppList.add(opp); } if(oppList.size()>0) insert oppList; List<Opportunity> oppListUpdate= new List<Opportunity>(); for(Opportunity opp:[SELECT StageName, CloseDate FROM Opportunity WHERE Name LIKE ‘TestOpp%’]) { opp.StageName=’Closed Won’; opp.CloseDate= Date.today()+12; oppListUpdate.add(opp); } PopulateOpportunityHandler.changeStage(oppList); if(oppListUpdate.size()>0) update … Read more

getting error while running a test class,error,Insert failed. REQUIRED_FIELD_MISSING

My controller class is public class Iapc { public boolean detailpage{set;get;} public boolean show{set;get;} public boolean hide{set;get;} public boolean editpage{set;get;} public boolean savepage {set;get;} public opportunity op{set;get;} public integer count{set;get;} public boolean app {set;get;} public string Fromlimit{set;get;} public string Tolimit{set;get;} public Boolean aprej {set;get;} public Boolean space{get;set;} public Boolean newrec{get;set;} public string idsparam{get;set;} public list<opportunity> … Read more

Apex Test Class coverage

I test my class and its 50% on trigger handler class, what can I do to cover the lines with the red code; My Class: public class AccountTriggerHandler { public static void updateContactAddresses(Map<ID, Account> updatedAccounts, Map<ID, Account> oldAccounts) { Set<Id> accountIds = new Set<Id>(); for (Account a : updatedAccounts.values()){ if(oldAccounts !=null) { //this is the … Read more

I am not able to pass values into Custom settings fields in test classes?

There are Three custom objects Property__c Fields: Name, Region__c, site__c Deal__c Fields: Name, Type__c,Manager__c,Property__c Project__c Fields: Name, OwnerId,Deal__c // all objects has master detail relationship to each other Custom Settings has been created to store to User id of specific Region__c (to avoid hard coding Id’s) Trigger Logic on Deal__c Custom object: If Type__c = … Read more

Method does not exist or incorrect signature invocable

Asked and answered here many times but I’m not finding this scenario. Getting method does not exist error when trying to invoke this Apex Class in my test. global with sharing class Invocable_ObjectEntityDefinition { global class Request{ @InvocableVariable(required=true) public String objectkey; } global class Response{ @InvocableVariable(required=false) public String entityObjectName; @InvocableVariable(required=false) public Id objectMdtId;} @InvocableMethod(label=’GetObjectName’) global … Read more

List has no rows while executed by system.runas()

I have a apex method which retrieves url parameters and perform SOQL and then DML operation. Here’s the apex method, public void updateObjRecord(){ try{ String objId = System.currentPageReference().getParameters().get(‘lid’); object__c objToUpdate = [Select Id, Name, Participated__c From object__c Where Id = :objId]; if (objToUpdate != null){ objToUpdate.Participated__c = true; upsert objToUpdate; } this.showSuccess = true; }catch(exception … Read more

How to create Operating Hours for Apex Testing

I can’t really find a solution for this, but does anyone can help me with creating Operating Hours for Apex Testing? I’m not quite sure what I have to create? Only the Operating Hours – record or more? Answer Apparantly it’s just enough to create a record for Operating Hours. OperatingHours oh = new OperatingHours(); … Read more

Batch Test class Constructor Not Defined problem [duplicate]

This question already has answers here: How to use trigger design pattern: ERROR Constructor not defined: [CaseTriggerHandler].<Constructor>() (2 answers) Closed 3 years ago. I have the following problem in a test class. Constructor not defined: [Soma_Dependentes_Update].<Constructor>() Test class of the batch process: @isTest public class Soma_Dependentes_UpdateTest { @isTest public static void testeit() { Account acc … Read more

Test classes for Scheduled Apex classes [duplicate]

This question already has an answer here: How do I increase my code coverage, or why can’t I cover these lines? (1 answer) Closed 3 years ago. Below I have shared the APEX code and the Test class code. I receive 100% code coverage, but I cannot grasp certain parts of it. Eg. The system.assert … Read more