• JoyJobing
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 12
    Replies

I'm leaving my company and wanted to update who gets these emails.  Does anyone know how to update this?  The other users are not developers so I don't think I could have them 'edit' the existing code so they're the last modified by...

I wrote a whole Task trigger around updating a field Last Activity by Account Owner.  Tested fine, and deployed, and I'm noticing it's not always working.  I've tracked the issue to the SOQL query (I think):

SELECT id, (SELECT id, ActivityDate, AccountId FROM Tasks WHERE Owner_Matches_Account_Owner__c = true AND IsClosed = true ORDER BY ActivityDate DESC LIMIT 1) FROM Account	WHERE id IN :dates.keySet()

 I know the list of ID's coming into the query is correct, but it looks like most times there are 0 results.

 

Based on the Task documentation (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_task.htm), it seems like this is set at some point (I made my trigger an AFTER to be sure):

AccountID: ID of the related Account.This is the account of WhatId if it exists, otherwise it’s the account of WhoId if it exists, otherwise it’s set to null. 

 

So far the Contacts are related to Accounts so I don't believe that's the issue.

 

Any thoughts?  I'm so stuck on this I'm going to have to comment the whole thing out and just do the update manually every day.  Argh.  PS - I originally got help writing this query from these boards here: http://boards.developerforce.com/t5/Apex-Code-Development/Select-newest-Task-from-Map-of-AcctId-s/m-p/643891#M119210

 

Edit: So far, what I've found is that the salesforce BCC logging email tasks work, and tasks that users add themselves do not work.  Neither is attached directly to the Account thru the Related To - only the Contact is filled in.

I'm trying to recreate Last Activity on the Account but need a few different parameters so built a Trigger.  My code is currently 

		List<Task> results = new List<Task> ([SELECT id, ActivityDate, AccountId FROM Task 												WHERE Owner_Matches_Account_Owner__c = true AND IsClosed = true AND AccountId IN :dates.keySet()												ORDER BY ActivityDate DESC LIMIT 1]);

 BUT I realized that this is giving me back only 1 result period...not 1 result per iD in the map keySet.  Is there a way to do this, or am I forced to make this NOT bulk safe, and throw the SELECT into a for loop around the map?

 

And I imagine that pulling ALL Tasks on each would be a bad idea - could be hundreds or thousands per Account.

 

Thanks in advance!

 

 I'm getting the following error on this line of code:  

Save error: Unexpected token: 'AND'

 

List<Task> newestTask = new List<Task> ([SELECT id, ActivityDate, AccountId FROM Task 													WHERE Owner_Matches_Account_Owner__c AND IsClosed AND ID in :ids									ORDER BY ActivityDate DESC LIMIT 1]);

 I know it must be obvious, but I can't figure out what's wrong with the multiple clauses in the WHERE section?  Any ideas?

We are looking at turning on Chatter in our org and I would like to pre-set the Email Settings for all the Users before we roll out to the org.  Of course we'll direct them to the page if they don't like our pre-selected choice, but I would like to get them started in this area (among many other areas).  Is this possible to access in the Data Loader?  I don't see what object it could be, when looking at the Schema using Eclipse...

I wrote a whole Task trigger around updating a field Last Activity by Account Owner.  Tested fine, and deployed, and I'm noticing it's not always working.  I've tracked the issue to the SOQL query (I think):

SELECT id, (SELECT id, ActivityDate, AccountId FROM Tasks WHERE Owner_Matches_Account_Owner__c = true AND IsClosed = true ORDER BY ActivityDate DESC LIMIT 1) FROM Account	WHERE id IN :dates.keySet()

 I know the list of ID's coming into the query is correct, but it looks like most times there are 0 results.

 

Based on the Task documentation (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_task.htm), it seems like this is set at some point (I made my trigger an AFTER to be sure):

AccountID: ID of the related Account.This is the account of WhatId if it exists, otherwise it’s the account of WhoId if it exists, otherwise it’s set to null. 

 

So far the Contacts are related to Accounts so I don't believe that's the issue.

 

Any thoughts?  I'm so stuck on this I'm going to have to comment the whole thing out and just do the update manually every day.  Argh.  PS - I originally got help writing this query from these boards here: http://boards.developerforce.com/t5/Apex-Code-Development/Select-newest-Task-from-Map-of-AcctId-s/m-p/643891#M119210

 

Edit: So far, what I've found is that the salesforce BCC logging email tasks work, and tasks that users add themselves do not work.  Neither is attached directly to the Account thru the Related To - only the Contact is filled in.

Im relatively new to Database queries, but the situation is for a little while we had an online scripts creating creating duplicate entries for the contact role in each opportunity created. That problem was fixed but now I just need to create a SOQL report of just the duplicates so I can go through and delete one of each.

This is the SOQL Query I try:

 

select ID, ContactID, OpportunityIDCOUNT(OpportunityID)

from OpportunityContactRole 

where Role != NULL

GROUP BY OpportunityID

HAVING COUNT(OpportunityID) > 1

 

This is returning the error:

 

MALFORMED_QUERY:
ContactID, OpportunityID, COUNT(OpportunityID)
^
ERROR at Row:1:Column:40
Grouped field should not be aggregated: OpportunityId

 

Can someone help me with this?

 

  • July 23, 2013
  • Like
  • 0

I'm trying to recreate Last Activity on the Account but need a few different parameters so built a Trigger.  My code is currently 

		List<Task> results = new List<Task> ([SELECT id, ActivityDate, AccountId FROM Task 												WHERE Owner_Matches_Account_Owner__c = true AND IsClosed = true AND AccountId IN :dates.keySet()												ORDER BY ActivityDate DESC LIMIT 1]);

 BUT I realized that this is giving me back only 1 result period...not 1 result per iD in the map keySet.  Is there a way to do this, or am I forced to make this NOT bulk safe, and throw the SELECT into a for loop around the map?

 

And I imagine that pulling ALL Tasks on each would be a bad idea - could be hundreds or thousands per Account.

 

Thanks in advance!

 

 I'm getting the following error on this line of code:  

Save error: Unexpected token: 'AND'

 

List<Task> newestTask = new List<Task> ([SELECT id, ActivityDate, AccountId FROM Task 													WHERE Owner_Matches_Account_Owner__c AND IsClosed AND ID in :ids									ORDER BY ActivityDate DESC LIMIT 1]);

 I know it must be obvious, but I can't figure out what's wrong with the multiple clauses in the WHERE section?  Any ideas?

Hi All,

 

I have a trigger that creates a task for a set of criteria on a custom object called Implementation. Whenever a non system admin user enters in the Target Go Live Date on the implementation record, the Trainer listed on the Implementation record will have a task created for them. Currently, whenever this trigger fires for the after update portion, it creates two duplicate tasks. I've crawled through several debug logs and toggled things on and off and found that if I turn off one specific workflow rule, the duplication does not occur. 

 

Any thoughts or ideas on why this particular workflow is causing the trigger to run twice?

 

Here's the workflow: (updates the Target Go Live Month field when the Target Go Live Date field is changed)

- Evaluate the rule when a record is created, and every time it's edited

- Object: Implementation

ISCHANGED( Target_Go_Live_Date__c)

- Field update:

- Field to update: Implementation: Target Go Live Month

CASE( TEXT( MONTH( Target_Go_Live_Date__c)), 
"1", "01 - Jan", 
"2", "02 - Feb", 
"3", "03 - Mar", 
"4", "04 - Apr", 
"5", "05 - May", 
"6", "06 - Jun", 
"7", "07 - Jul", 
"8", "08 - Aug", 
"9", "09 - Sep", 
"10", "10 - Oct", 
"11", "11 - Nov", 
"12", "12 - Dec", 
"")

 

Here's the trigger:

trigger TargetGoLiveDateTrainerTask on Implementation_del__c (after insert, after update) {
  List<Task> tasks = new List<Task>();
  Id currentUserProfileId = UserInfo.getProfileId();
  Set<Id> implementationIds = new Set<Id>();
  Date taskDate = System.today();
  RecordType recordType = RecordTypeResolver.find('Task', 'Client Services');
  
  //Exclude all System Admins from creating this task
  if (new Set<Id> {'00e30000000dSKN'}.contains(currentUserProfileId))
    return;

  for (Integer i = 0; i < Trigger.size; i++) {

    if ((Trigger.isInsert || Trigger.old[i].Target_Go_Live_Date__c == null) &&
      (Trigger.new[i].Target_Go_Live_Date__c != null &&
       Trigger.new[i].Training_Required__c != 'No'))
        
      implementationIds.add(Trigger.new[i].Id);
  }
  
  if( implementationIds != null) {

    List<Implementation_del__c> implementations = new List<Implementation_del__c>([SELECT Id, Account__c, Trainer__c, Account__r.Name, Target_Go_Live_Date__c FROM Implementation_del__c WHERE Id IN :implementationIds]);
  
    for (Implementation_del__c implementation : implementations) {

      if (implementation.Trainer__c == null) {
        implementation.addError('Implementation has no Trainer set.  Please set a Trainer for the \'Training Kick Off Call\' Task to continue.  Contact an administrator for more information.');
      }

      else if (System.today().daysBetween(implementation.Target_Go_Live_Date__c) < 30) {
        tasks.add( new Task( Subject = 'Training Kick Off Call: ' + (implementation.Account__c != null ? implementation.Account__r.Name : '<Unknown>'),
                  OwnerId = implementation.Trainer__c,
                  ActivityDate = taskDate,
                   ReminderDateTime = System.today(),
                  IsReminderSet = True,
                  WhatId = implementation.Id,
                  RecordTypeId = recordType.Id ));
      }
      
      else {
        taskDate = implementation.Target_Go_Live_Date__c - 30;
        tasks.add( new Task( Subject = 'Training Kick Off Call: ' + (implementation.Account__c != null ? implementation.Account__r.Name : '<Unknown>'),
                 OwnerId = implementation.Trainer__c,
                 ActivityDate = taskDate,
                 ReminderDateTime = DateTime.newInstance(taskDate, Time.newInstance(8, 0, 0, 0)),
                 IsReminderSet = True,
                 WhatId = implementation.Id,
                 RecordTypeId = recordType.Id ));
      }
    }
    
    if(tasks != null)
      insert tasks;
  }