• PaulJS
  • NEWBIE
  • 20 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
I have an object, Object1__c, that has a lookup relationship to the account object.  Also on Object1__c is a picklist field that is used to indicate the outcome of a call (declined, no answer, etc.).

On the account object I have then placed a number of custom fields that will be used to house the count of each outcome value for Object1 records related to that account.

In my trigger on Object1, I am able to populate the appropriate custom field on the account object using this code as an example:
 
List<Account> aToUpdate = new List<Account>();

for(Account a : [SELECT Id, Declined__c, (SELECT Id, Outcome__c FROM Object1s__r WHERE Disposition__c = 'Declined') FROM Account WHERE Id IN :acctSet]){

    a.Declined__c = a.Object1s__r.size();                 
    aToUpdate.add(a);      
          
}

Update aToUpdate;
...but doing it this way doesn't feel right as I'd then have a separate SOQL query for each outcome value.  

Is there a way to do this with one query?  I thought something along the lines of AggregateResult might be appropriate, but am having trouble then ensuring that I pull the correct values based on the individual account Ids found in my set of account Ids (acctSet).

Any help would be appreciated.
 
  • November 20, 2014
  • Like
  • 0
I have a trigger in which I am assigning IDs to a list when the trigger is fired.  When I run a query against this list using WHERE ID IN:, the query does not return any duplicate values, which is causing a list index out of bounds error.

Here is my code for the assignment of the IDs to the initial list.

List<String> whatIDs = new List<String>();
   
    for (Task tk : Trigger.new){
       
        whatIDs.add(tk.whatID);
    }

And here is my code querying another object where the ID is found in that list.

List<Object1__c> oblist =  [SELECT ID, Name
                                                  FROM Object1__c
                                                  WHERE ID IN :whatIDs];

During testing, I had a list of 26 records in my initial list (whatIDs), but because my query is not returning duplicate values (there is one), I am only getting back 25 records.

Can anyone offer any suggestions/help?

Thanks.

-Paul
  • April 22, 2014
  • Like
  • 0
I have two custom objects:

object1__c is a list of offices
object2__c is a list of employees, and each record on this object is related to object1__c through a lookup relationship field.

When an activity is logged against either of those objects, I want to update a custom field (related__c) on the task object that will include the office name from object1__c.  I'd assumed this would be relatively easy to do via the relationship between the two, but I'm stuck.  

I've been able to accomplish this through the use of two seperate simple field update triggers, but it seems to me there has to be a way to do it with one.  Can anyone provide any guidance?

I am looking to do this such that I can report on all activities that are in any way related to the office, whether they be logged against the office itself or one of the employees of that office.  From what I can tell, you can report on "activites with object1" or "activities with object2," but not both in a way that they can easily be grouped together.

Thanks.
  • April 20, 2014
  • Like
  • 0
Hi - I am trying to work on my first trigger and could use some guidance.

I have a custom object (object__c) into which records are being bulk uploaded/inserted.  There is a particular field on this object (appt__c) that includes a code (sometimes abbreviated text, sometimes alphanumeric, etc.) that corresponds to an appointment type.  

I am trying to update a second field on the record (text__c) with a more "readable" text-version of the appointment type.  For example, if "ov" is uploaded into the appt__c field, I want to update the text__c field with "office visit."  There usually will be, however, multiple codes that correspond with the same text version.  For example, all of the following might equal "office visit": "ov," "ov(15)," "office."

This seems like a relatively simple issue, but I can't seem to get to the answer.  Anyone willing to offer any suggestions?

(p.s. I am currently doing this with a field replacement workflow, but there are so many apppointment type codes that I keep running up against limits in my field update formula.) 


  • January 26, 2014
  • Like
  • 0
We have two custom objects: Task_Custom__c and Timeslip__c.
Timeslip contains these fields:
"Total_Billable_Time__c" (hours)
"Related_Task__c" (a lookup on the Task_Custom__c object)

Therefore when viewing a Task, it gives a list of all related Timeslip's.  
What I want to do is have a field on the Task_Custom__c object "Billable_Time__c" which would be a summary of all "Total_Billable_Time__c" from all related Timeslips.  I can't do a rollup summary because it's a cross object reference.  Is there a way to write an apex trigger for the TimeSlip object that would update the "Billable_Time__c" field on a Task anytime a timeslip is created or updated that is related to that Task?
I have an object, Object1__c, that has a lookup relationship to the account object.  Also on Object1__c is a picklist field that is used to indicate the outcome of a call (declined, no answer, etc.).

On the account object I have then placed a number of custom fields that will be used to house the count of each outcome value for Object1 records related to that account.

In my trigger on Object1, I am able to populate the appropriate custom field on the account object using this code as an example:
 
List<Account> aToUpdate = new List<Account>();

for(Account a : [SELECT Id, Declined__c, (SELECT Id, Outcome__c FROM Object1s__r WHERE Disposition__c = 'Declined') FROM Account WHERE Id IN :acctSet]){

    a.Declined__c = a.Object1s__r.size();                 
    aToUpdate.add(a);      
          
}

Update aToUpdate;
...but doing it this way doesn't feel right as I'd then have a separate SOQL query for each outcome value.  

Is there a way to do this with one query?  I thought something along the lines of AggregateResult might be appropriate, but am having trouble then ensuring that I pull the correct values based on the individual account Ids found in my set of account Ids (acctSet).

Any help would be appreciated.
 
  • November 20, 2014
  • Like
  • 0
I have a trigger in which I am assigning IDs to a list when the trigger is fired.  When I run a query against this list using WHERE ID IN:, the query does not return any duplicate values, which is causing a list index out of bounds error.

Here is my code for the assignment of the IDs to the initial list.

List<String> whatIDs = new List<String>();
   
    for (Task tk : Trigger.new){
       
        whatIDs.add(tk.whatID);
    }

And here is my code querying another object where the ID is found in that list.

List<Object1__c> oblist =  [SELECT ID, Name
                                                  FROM Object1__c
                                                  WHERE ID IN :whatIDs];

During testing, I had a list of 26 records in my initial list (whatIDs), but because my query is not returning duplicate values (there is one), I am only getting back 25 records.

Can anyone offer any suggestions/help?

Thanks.

-Paul
  • April 22, 2014
  • Like
  • 0
I have two custom objects:

object1__c is a list of offices
object2__c is a list of employees, and each record on this object is related to object1__c through a lookup relationship field.

When an activity is logged against either of those objects, I want to update a custom field (related__c) on the task object that will include the office name from object1__c.  I'd assumed this would be relatively easy to do via the relationship between the two, but I'm stuck.  

I've been able to accomplish this through the use of two seperate simple field update triggers, but it seems to me there has to be a way to do it with one.  Can anyone provide any guidance?

I am looking to do this such that I can report on all activities that are in any way related to the office, whether they be logged against the office itself or one of the employees of that office.  From what I can tell, you can report on "activites with object1" or "activities with object2," but not both in a way that they can easily be grouped together.

Thanks.
  • April 20, 2014
  • Like
  • 0
Hi - I am trying to work on my first trigger and could use some guidance.

I have a custom object (object__c) into which records are being bulk uploaded/inserted.  There is a particular field on this object (appt__c) that includes a code (sometimes abbreviated text, sometimes alphanumeric, etc.) that corresponds to an appointment type.  

I am trying to update a second field on the record (text__c) with a more "readable" text-version of the appointment type.  For example, if "ov" is uploaded into the appt__c field, I want to update the text__c field with "office visit."  There usually will be, however, multiple codes that correspond with the same text version.  For example, all of the following might equal "office visit": "ov," "ov(15)," "office."

This seems like a relatively simple issue, but I can't seem to get to the answer.  Anyone willing to offer any suggestions?

(p.s. I am currently doing this with a field replacement workflow, but there are so many apppointment type codes that I keep running up against limits in my field update formula.) 


  • January 26, 2014
  • Like
  • 0