+ Start a Discussion
Harshal Patil 15Harshal Patil 15 

i just want to write same trigger for this object (customer__c,invoices__c) how to to do that

trigger eventTrigger on event (after insert,after delete,after undelete){

set<id> setid = new set<id>();
List<lead> leadlist = new List<lead>();

if(trigger.isInsert  ||  trigger.isUndelete){
for(event e : trigger.new){
if(string.valueof(e.whoid).startswith('00Q')){
setid.add(e.whoid);
}

}

}


if(trigger.isDelete){
for(event e : trigger.old){
if(string.valueof(e.whoid).startswith('00Q')){
setid.add(e.whoid);

}

}

}

for(lead l : [select id,No_of_Events__c,(select id from events) from lead where id in : setid]){
lead ll = new lead();
ll.id=l.id;
ll.no_of_events__c = l.events.size();
leadlist.add(ll);
}
update leadlist;
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Harshal,

Can you elaborate on the scenario you are trying to solve as that way we can check this further and respond back.

Looking forward to your response.

Thanks.