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
ahmay85ahmay85 

Trigger on event that update the Opportunity Object

I have 2 custom field which on Opportunity (Meeting_Event_Completed__c,Meeting_Event_Exist__c), both default value is False (using checkbox datatype).

When the user creata new event

After Insert/Update: If Event Type = 'Virtual Meeting' or 'Face to Face Meeting', Update Opportunity.Meeting Event Created = True
If Event Type = ('Virtual Meeting' or 'Face to Face Meeting') and Status = 'Held', Update Opportunity.Meeting Event Completed = True

 

The Apex Code and the Trigger Still got problem, can help me?

 

Apex Code:

public class OpportunityClass
{
    public static void validateOpportunity(Event[] evts)
    {
        for (Event a:evts)
        {
            if (a.Event_Type__c== 'Virtual Meeting' || a.Event_Type__c=='Face to Face Meeting')           
            {
                if (a.Event_Status__c<>'Held')
                {
                    //Update Opportunity.Meeting Event Created = True
                    Opportunity opp = new Opportunity();
                    opp=[select opportunity.Meeting_Event_Exist__c from Opportunity where Name='Test'];
                    opp.Meeting_Event_Exist__c=True;
                    update opp.Meeting_Event_Exist__c;
                }
                else
                {
                    Opportunity opp = new Opportunity();
                    opp=[select opportunity.Meeting_Event_Exist__c from Opportunity where Name='Test'];
                    opp.Meeting_Event_Completed__c=True;
                    update opp.Meeting_Event_Completed__c;
                }
            }
        }
            
    }
}

 

Trigger on Event:

trigger eventOpportunityTrigger on Event(after insert, after update)
{
    Event[] vet= Trigger.new;
    OpportunityClass.validateOpportunity(vet);
}