• Shiva Gadigas
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

HI all, 

 

can any body help me in the following code.

 

I am new to apex code..

 

trigger EventComplete_Opportunity on Event (after insert,after update) {

Map <Id, String> OppStatus = new Map <Id, String>();
Map <Id, String> OppStatusS = new Map <Id, String>();
List <Opportunity> OppToUpdate = new List <Opportunity>();
List <Opportunity> OppToUpdateS = new List <Opportunity>();
set<ID> OPPTaskIDS = new set<ID>();
String Last_Activity;
Date Last_Activity_Date;
String Next_Step;
Date Next_Step_Date;
DateTime ComEndDtae=datetime.now() ;

for(Event e : trigger.new) {
if(e.whoId != null) {
String x = e.whoId;
// 006 is a Opportunity
if (x.substring(0,3) == '006' ){
OppStatus.put(e.whoId,e.Subject);
Last_Activity = e.Subject;
Last_Activity_Date = date.today();
}
}

for(Opportunity o : [Select id, Last_Activity__c, Last_Activity_Date__c from Opportunity where id in :OppStatus.keyset()]) {
o.Last_Activity__c = Last_Activity;
o.Last_Activity_Date__c = Last_Activity_Date;
OppToUpdate.add(o);
}

if(OppToUpdate.size() > 0)
update OppToUpdate;
OppToUpdate.clear();


if(e.whatid<>null){
OPPTaskIDS.add(e.whoId);
}


if(OPPTaskIDS.size()>0){

for(Opportunity o: [Select o.Id, o.Next_Step__c, o.Next_Step_Due_Date__c,
(Select Id, Subject,ActivityDate From Events ORDER BY StartDateTime ASC)
From Opportunity o where Id in :OPPTaskIDS]){

o.Next_Step__c = o.Events[0].Subject;
o.Next_Step_Due_Date__c = o.Events[0].ActivityDate;
OppToUpdateS.add(o);
}
}

if(OppToUpdateS.size() > 0)
update OppToUpdateS;
OppToUpdateS.clear();

}
}

 

 

But after completion of Events based on date..still it is showing as Next Activity and Next activity Due date..

 

Please help me out from this...

 

Thanks in Advance!!!

HI all, 

 

can any body help me in the following code.

 

I am new to apex code..

 

trigger EventComplete_Opportunity on Event (after insert,after update) {

Map <Id, String> OppStatus = new Map <Id, String>();
Map <Id, String> OppStatusS = new Map <Id, String>();
List <Opportunity> OppToUpdate = new List <Opportunity>();
List <Opportunity> OppToUpdateS = new List <Opportunity>();
set<ID> OPPTaskIDS = new set<ID>();
String Last_Activity;
Date Last_Activity_Date;
String Next_Step;
Date Next_Step_Date;
DateTime ComEndDtae=datetime.now() ;

for(Event e : trigger.new) {
if(e.whoId != null) {
String x = e.whoId;
// 006 is a Opportunity
if (x.substring(0,3) == '006' ){
OppStatus.put(e.whoId,e.Subject);
Last_Activity = e.Subject;
Last_Activity_Date = date.today();
}
}

for(Opportunity o : [Select id, Last_Activity__c, Last_Activity_Date__c from Opportunity where id in :OppStatus.keyset()]) {
o.Last_Activity__c = Last_Activity;
o.Last_Activity_Date__c = Last_Activity_Date;
OppToUpdate.add(o);
}

if(OppToUpdate.size() > 0)
update OppToUpdate;
OppToUpdate.clear();


if(e.whatid<>null){
OPPTaskIDS.add(e.whoId);
}


if(OPPTaskIDS.size()>0){

for(Opportunity o: [Select o.Id, o.Next_Step__c, o.Next_Step_Due_Date__c,
(Select Id, Subject,ActivityDate From Events ORDER BY StartDateTime ASC)
From Opportunity o where Id in :OPPTaskIDS]){

o.Next_Step__c = o.Events[0].Subject;
o.Next_Step_Due_Date__c = o.Events[0].ActivityDate;
OppToUpdateS.add(o);
}
}

if(OppToUpdateS.size() > 0)
update OppToUpdateS;
OppToUpdateS.clear();

}
}

 

 

But after completion of Events based on date..still it is showing as Next Activity and Next activity Due date..

 

Please help me out from this...

 

Thanks in Advance!!!