You need to sign in to do that
Don't have an account?
I am trying to Update Opportunity Based on Event Field. But getting issue to validation two condition at same time
Hi, I have written helper class for updating opportunity. if Event Status = 'Cancelled' then I am updating opportunity Stage Field else if Event Type = 'Consultation'. then I updating Opportunity Date field. I am trying to update both logic if both matching matched.
This the class I have written.
This the class I have written.
- public class EventHandler{
- public static void OpportunityStageUpdateBaseOnEventStatus (List<Event> evnList){
- Boolean condition1=false;
- Boolean condition2=false;
- Map<Id,Event> mapID = new Map<Id,Event>();
- Set<Opportunity> OppSet = new Set<Opportunity>();
- for(Event evn: evnList){
- mapID.put(evn.Id,evn);
- }
- System.debug('mapID'+mapID);
- for(Event evn: mapID.values()){
- if(evn.Type__c == 'Consultation'){
- System.debug('1');
- condition1=true;
- Opportunity opp = new Opportunity();
- opp.Id = evn.WhatId;
- Opp.Demo_Date_Time__c = evn.StartDateTime;
- OppSet.add(opp);
- }else if(evn.Status__c == 'cancelled'){
- System.debug('2');
- condition2=true;
- Opportunity opp = new Opportunity();
- opp.Id = evn.WhatId;
- Opp.StageName = 'Closed Lost';
- OppSet.add(opp);
- }else if(condition1 ==true && condition2 ==true){
- System.debug('3');
- Opportunity opp = new Opportunity();
- opp.Id = evn.WhatId;
- Opp.Demo_Date_Time__c = evn.StartDateTime;
- Opp.StageName = 'Closed Lost';
- OppSet.add(opp);
- }
- }
- if(OppSet.Size()>0){
- System.debug('SIZE >>'+OppSet.Size());
- update new List<Opportunity>(OppSet);
- System.debug('SIZE >>'+OppSet);
- }
- }
- }
can you please make me understand what do you mean by :-
I am trying to update both logic if both matching matched what do you mean by this?
Like if Event Status = 'Cancelled' and Event Type = 'Consultation' both field are updated at the same time then I want to update these two Demo_Date_Time__c and StageName, and if Event Status = 'Cancelled' updated only then update Demo_Date_Time__c only. else
if Event Type = 'Consultation' updated only then update StageName.
Write Trigger on parent as well as on child object and perform operations from there..