function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jojo5jojo5 

how to compare old values of eventrelation

Hi, can someone please show me examples of how to compare old and new values using the EventRelation Object? Is this even possible? I just want to get the old values of the isParent and isInvitee.
Below is what I was trying out, but it gives me an error.

Method does not exist or incorrect signature: void get(Boolean) from the type Map<Id,SObject>

for (EventRelation er: eLst) {
        EventRelation oldOpp = Trigger.oldMap.get(er.EventId);
}
 
Best Answer chosen by jojo5
AbhishekAbhishek (Salesforce Developers) 
Try this for the above error,

https://developer.salesforce.com/forums/?id=9060G0000005jRXQAY

To see if the value is changed or not we would need fields prior value in apex trigger. To compare the old value and new value in trigger we can use trigger a new map and trigger an old map. Basically, to compare old field value of record with the new value in trigger we need to access trigger. oldmap and trigger.

For further reference,

https://www.cloudforce4u.com/2013/07/compare-old-and-new-values-in-trigger.html

https://www.sfdc99.com/2014/02/25/comparing-old-and-new-values-in-a-trigger/

Thanks!




 

All Answers

AbhishekAbhishek (Salesforce Developers) 
Hi JoJo,

Try the suggestions as mentioned in the developer blog,

https://developer.salesforce.com/forums/?id=906F0000000BY6yIAG

https://developer.salesforce.com/forums/?id=9060G000000XdimQAC

It might help you.

Thanks!
jojo5jojo5
Hi Abhishek,
Thank you for your suggestion. I am new to salesforce development and trying my best to understand how this works, but I am afraid I am stuck and lost. I followed the links you provided and tried it in my environemnt. I just want to compare the old and new value so I can make an update. Will you be able to help me?


in my trigger i set the following:
    if (Trigger.isBefore){
        if (Trigger.isUpdate){       
            EventTrigger.eventUpdateContact(Trigger.oldMap, Trigger.newMap);
        }

in my class I did the following
    public static void eventUpdateContact(Set<Id> OldMap, Set<Id> NewMap){
         List<EventRelation> eventLst= [SELECT isParent, isInvitee, RelationId
                                                FROM EventRelation 
                                                WHERE EventId IN :NewMap
                                                ];    
        
        for(EventRelation e : eventLst){
            if(OldMap.get(e.EventId).isParent == true && NewMap.get(e.EventId).isParent == true){
                
            }
else{

}
           
        }
    }

i get errro: I get an errror Method does not exist or incorrect signature: void get(Boolean) from the type Set<Id>
AbhishekAbhishek (Salesforce Developers) 
Try this for the above error,

https://developer.salesforce.com/forums/?id=9060G0000005jRXQAY

To see if the value is changed or not we would need fields prior value in apex trigger. To compare the old value and new value in trigger we can use trigger a new map and trigger an old map. Basically, to compare old field value of record with the new value in trigger we need to access trigger. oldmap and trigger.

For further reference,

https://www.cloudforce4u.com/2013/07/compare-old-and-new-values-in-trigger.html

https://www.sfdc99.com/2014/02/25/comparing-old-and-new-values-in-a-trigger/

Thanks!




 
This was selected as the best answer