• PenchuReddy
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hello

I have been directed here for some help from Answers 

I am looking for help creating a button that sits in the list view of both Accounts and Contacts that allows me to change owner on both objects simultaneously regardless of the object list view I in. 

I have been advised I need to write a VF page but I'm afraid I am not a developer. 

Can anyone help or who use such a function? Appreciate in advance. 

Marc 

 

Hi All,

 

I have the below code that counts the number of a certain type of activity related to a given record. I want to update this to also pull in the date of the most recent task that is in the list. I have added a command to sort the tasks by date, but I'm getting stuck on how to select the most recent date of the generated list and populate that on the lead/contact record. Can anyone help with this?

 

Thanks!

 

trigger UpdateLeadContactOppDemoDeliveredTasks on Task (after delete, after insert, after undelete,
after update) {

// Updated on 2.28.13 to include only leads and contacts - opportunities were separated out


// Declare the variables

public set<Id> LeadIDs = new Set<Id>();
public list<Lead> LeadsToUpdate = new List<Lead>();
public set<Id> ContactIDs = new Set<Id>();
public list<Contact> ContactsToUpdate = new List<Contact>();




// Build the list of Leads and Contacts to update
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
    for(Task t: Trigger.new){
    if(t.whoid!=null && string.valueOf(t.WhoId).startsWith('00Q'))
    LeadIDs.add(t.WhoId);
    if(t.whoid!=null && string.valueOf(t.WhoId).startsWith('003'))
    ContactIDs.add(t.WhoId);


    }
}

if(Trigger.isDelete || Trigger.isUpdate){
    for(Task t: Trigger.old){
    if(t.whoid!=null && string.valueOf(t.WhoId).startsWith('00Q'))
    LeadIDs.add(t.WhoId);
    if(t.whoid!=null && string.valueOf(t.WhoId).startsWith('003'))
    ContactIDs.add(t.WhoId);
    }
}

// Update the Leads

if(LeadIDs.size()>0){
for(Lead l: [Select l.Id, l.Demos_Delivered_Count__c,
(Select Id, ActivityDate From Tasks where Status = 'Demo Delivered' Order by ActivityDate DESC )
From Lead l where Id in :LeadIDs])
LeadsToUpdate.add(new Lead(Id=l.Id, Demos_Delivered_Count__c = l.Tasks.size()));
update LeadsToUpdate;
}
if(LeadstoUpdate != null && !LeadsToUpdate.isEmpty())
Database.update(LeadsToUpdate);

// Update the Contacts

if(ContactIDs.size()>0){
for(Contact c: [Select c.Id, c.Demo_Delivered_Count__c,
(Select Id, ActivityDate From Tasks where Status = 'Demo Delivered' Order by ActivityDate DESC)
From Contact c where Id in :ContactIDs])
ContactsToUpdate.add(new Contact(Id=c.Id, Demo_Delivered_Count__c  = c.Tasks.size()));
update ContactsToUpdate;
}
if(ContactstoUpdate != null && !ContactsToUpdate.isEmpty())
Database.update(ContactsToUpdate);


}