Questions tagged [trigger-oldmap]

A map of IDs to the old versions of the sObject records. Note that this map is only available in update and delete triggers.

Filter by
Sorted by
Tagged with
-2 votes
2 answers
247 views

My trigger is not working

I tested by editing my order object and then populating a description when it runs. trigger OrderTrigger1 on Order (before insert) { switch on Trigger.operationType { when BEFORE_UPDATE { ...
FaThima Hussain's user avatar
-6 votes
2 answers
139 views

Getting error in trigger recursion for example if I create account and than update it. It will give me the concatenation of both insert one and update

Trigger accpre on account(before insert, before update){ list<account> acclist=new list<account>(); for(Account acc:Trigger.new){ if(acc.phone!=Trigger.oldMap.get(acc.id)....
Rohan Dadamode's user avatar
0 votes
1 answer
582 views

Test Class Coverage for Trigger with oldMap

I have an Apex Trigger and Handler class on the Business Process object. When a lookup field (Financial_Planner__c) is updated on the Business Process, the system should query all Tasks associated to ...
tonydigi1's user avatar
-3 votes
1 answer
1k 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 ...
Fatih's user avatar
  • 1
0 votes
1 answer
445 views

Trigger to update a Lookup Record when status field is updated

I am trying to solve a simple problem. I have an object Service_Expansion_Tracker__C, there is a lookup field NHC_Tracker__c on the object (The relation between NHC tracker and Service Expansion ...
Niraj Dev's user avatar
0 votes
2 answers
947 views

Trigger.oldMap return error "Variable does not exist"

I am writing a class using Trigger.oldmap to find old account ownerId but it does not recognize what OwnerId is. (Trigger.oldMap.get(acc.Id)).OwnerId The script is trying to create a custom "...
Felix Fong's user avatar
0 votes
1 answer
626 views

Unable to insert and update for trigger.oldmap and Trigger.newmap in apex trigger

I have an object called log__c in that fields have Description__c, Action__c(label name :Title) Lookup with Contact object, when I change the phone field of contact the object then in log__c object ...
user avatar
0 votes
0 answers
73 views

Apex trigger not step in isUpdate

In the following apex trigger it does not step in isUpdate. It works properly in case of new insertion or deletion, but in case of update it does not removes the old ID from the list. As per the debug ...
Lilla Székely's user avatar
2 votes
2 answers
1k views

Comparing old and new field value from Map<Id,Sobject>

I am pretty new to development and I am trying to user Chris Aldridge's Lightweight Trigger Framework http://chrisaldridge.com/triggers/lightweight-apex-trigger-framework/. I am looking to create a ...
LMills's user avatar
  • 23
2 votes
1 answer
385 views

Do trigger.newMap and trigger.oldMap have the same keySet() in apex after update triggers?

My potential use case by knowing the answer to this question would be, if I'm working with a legacy code and I can't make modification to the method signature and I only have access to trigger.new and ...
Bahman.A's user avatar
  • 828
0 votes
2 answers
2k views

How to compare fields of oldMap and newMap?

I have a trigger helper with this method: public void changeObjects(Map<Id, Cleaning__c> oldObjectsMap, Map<Id, Cleaning__c> newObjectsMap) But it should make changes only if ...
Dan Dan's user avatar
  • 45
0 votes
2 answers
820 views

Trigger.OldMap returns new Value

When a contact is updated, i want to know the old value of the owner. This is how I am testing --- Changed Owner on Account, as a result, owner on Contact changed to be the same as Account Owner. The ...
GroundToCloud's user avatar
0 votes
1 answer
380 views

Trigger Compare Old and New AccountOwner of a Contact

I am having trouble comparing the old and new owner of the Account associated with the contact to achieve #6 of the requirement. Can someone please suggest how I satisfy condition #6 in the logic. ...
GroundToCloud's user avatar
0 votes
1 answer
280 views

I want to update Checkbox(Custom Field) on Contact whenever a new Opportunity is created based on Contact in (Primary_Contact__c)

I want to update Custom Field(Checkbox) on Contact whenever a new Opp is created and Opp has Primary Contact from Contact trigger PrimaryConOnAccOfOppHandler on Opportunity (after insert, after ...
SFDC_M's user avatar
  • 63
2 votes
2 answers
1k views

trigger to update Custom field on Account record whenever a new opportunity record (Whose Title contains 'CEO') is inserted or deleted

Trigger to update Custom field(Count_Of_Title_in_Opp__c) on Account record whenever a new opportunity record (Whose Title contains 'CEO') is inserted or deleted Trigger trigger OppSizeOnAccount on ...
Dave's user avatar
  • 480
1 vote
1 answer
383 views

is it possible to get the parents old value in trigger update on junction object

i have a issue in retrieving the old value of parents record onthe junction object update scenario, do anyone have come across this scenario, please throw lights. Junction__c oldlrj = [SELECT Id, ...
user8132's user avatar
  • 343
0 votes
2 answers
80 views

Field of new records not updated by trigger

I'm new to apex and trigger and have an issue. I need to update a field on a record when 2 other fields are updated. This field is supposed to calculate the time between 2 dates based on the business ...
chloe's user avatar
  • 243
0 votes
2 answers
298 views

Need to Understand Apex trigger soql execution on each events

I have a trigger handler as shown below (Please Ignore any Syntax errors) trigger AccountTrigger on Account (after delete, after insert, after undelete, after update, before delete, before insert, ...
Sam's user avatar
  • 21
1 vote
1 answer
4k views

How to cover trigger.oldmap.get () in test class

public void updateAccessLevelsOnUpdate(final List<Opportunity> newOppList, Map<Id, Opportunity> oldOppMap){ if(Istrue == true){ try{ Map<Id, Id> ...
user avatar
0 votes
2 answers
35 views

Can I avoid a code duplication here?

I have a code duplication here. How can I fix it? I want to make my code better. Helper: public with sharing class JobHelper { List<Task> taskList = new List<Task>(); public void ...
Monte Cristo's user avatar
0 votes
1 answer
1k views

Custom History Tracking on Opportunity with trigger

Trigger:   Custom Opportunity History Tracking Create Custom Object : OpportunityHistory Fields : Field Name(Text), Old Value(Text) and New Value(Text) Trigger Logic:    • When new opportunity ...
PiK's user avatar
  • 15
0 votes
1 answer
348 views

Does OldMap Change During Recursion?

I wrote some code on Opportunity that compares new values to OldMap values and should execute a record clone only if the record was JUST Closed Lost. I'm not sure if my interpretation of OldMap is ...
Morgan Marchese's user avatar
1 vote
1 answer
2k views

Test coverage for comparing old versus new value on Opportunity

I am attempting to cover for apex code that compares if a particular value on the Opportunity object has increased since the Opportunity was updated. This is a before update trigger, which may be a ...
COBETCKNN17's user avatar
0 votes
1 answer
55 views

How to get PermissionSet oldMap value and compare with new one in after update trigger

I need to figure out if values in PermissionSet for current user are changed in trigger, i'm thinking about using oldMap but i can't figure it out. Maybe this code will explain what i'm trying to do: ...
Nikola Naumovski's user avatar
0 votes
1 answer
558 views

after update Trigger using oldMap not working

This Trigger is being created to update a lookup field on Contact if the Contacts Community account is disabled. I have a field on Contact called Support_Community_User__c that is a lookup to User ...
Jason's user avatar
  • 832
0 votes
2 answers
40 views

Getting error when trying to compare between old and new values

I'm trying to see if the Priority value on Case changed but I get the error below and I can't figure out why. for(Case c: (List<Case>)Trigger.New) { if(setRecordTypeIds.contains(...
Json's user avatar
  • 1,587
0 votes
1 answer
926 views

Trigger to fire when a checkbox is updated/inserted to read true

I have a trigger that i want to fire when a checkbox is set as true: The conditions of my If statement are as follows: c.DetailsConfirmed__c == true && trigger.oldmap.get(c.id)....
denisoleary's user avatar
1 vote
2 answers
444 views

test class error - attempt to de-reference a null object Trigger using oldmap

I am receiving an Error in my Test class, but am unsure of the reason why. Here is the Error: Exception: Update failed. First exception on row 0 with id a0i4C000000HfieQAC; first error: ...
Starley Flynn's user avatar
1 vote
1 answer
9k views

Issue with APEX Trigger.OldMap. OldMap is giving new value of the field(Stage) instead of the Old Value

trigger MasterOpportunityTrigger on Opportunity(before insert, after insert, before update, after update, before delete, after delete,after undelete) { if (Trigger.IsAfter) { else if (Trigger....
Kiran's user avatar
  • 111
4 votes
1 answer
776 views

Is there a way to retrieve the oldMap of a trigger in a future method?

This could be quite a dumb question though, I would like to ask is there a way to retrieve the oldMap of a trigger in a @future method? In the below code please refer the collection "...
Hasantha's user avatar
  • 2,045