• Jon Foy
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 27
    Replies
We have a custom object "Task_Custom__c" that I would like to add a button to.  When the button is clicked, we need two fields on this object to be updated:

Completion_Stats__c = "Completed"
Completion_Percentage__c = "100"

Can that be done with on click javascript?
I have the following trigger that adds a member to the case team, whenever a custom object "Case_Resource__c" is added to the Case.  The only problem is, the Resource_Name__c on the Case_Resource__c is a lookup value of the Contact object.  So when the Trigger creates a case team memeber, it is created as a Contact.  I want it to be created as a User, or Partner User.

Is there a way to update this code so that the Case Team Memeber Added is for the UserId (or Name...not sure which one) that matches the Contact Name?

trigger CaseResource_CaseTeamMemberCreation on Case_Resource__c (after insert) {
    CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Team Member'];
    List<CaseTeamMember> members = new List<CaseTeamMember>();
   
    for (Case_Resource__c resource: Trigger.new) {
        if (resource.Resource_Name__c != null && resource.Case__c != null) {
            members.add(new CaseTeamMember(
                ParentID = resource.Case__c,
                MemberID = resource.Resource_Name__c,
                TeamRoleID = role.Id

           ));
        }
    }
   
    if (!members.isEmpty()) {
        insert members;
    }
   

}
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 the following trigger that adds a member to the case team, whenever a custom object "Case_Resource__c" is added to the Case.  The only problem is, the Resource_Name__c on the Case_Resource__c is a lookup value of the Contact object.  So when the Trigger creates a case team memeber, it is created as a Contact.  I want it to be created as a User, or Partner User.

Is there a way to update this code so that the Case Team Memeber Added is for the UserId (or Name...not sure which one) that matches the Contact Name?

trigger CaseResource_CaseTeamMemberCreation on Case_Resource__c (after insert) {
    CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Team Member'];
    List<CaseTeamMember> members = new List<CaseTeamMember>();
   
    for (Case_Resource__c resource: Trigger.new) {
        if (resource.Resource_Name__c != null && resource.Case__c != null) {
            members.add(new CaseTeamMember(
                ParentID = resource.Case__c,
                MemberID = resource.Resource_Name__c,
                TeamRoleID = role.Id

           ));
        }
    }
   
    if (!members.isEmpty()) {
        insert members;
    }
   

}
I have the following Code.  It updates a custom object (TimeSlip), anytime it is saved.  98% of the time a user will save their own timecards, and it works perfectly.  However, in some rare cases, another user will need to update a timeslip.  In these cases, the "Case_Resource__ID" on the TimeSlip is being updated to the Case Resource ID where the Resrouce Name, matches the current user...it should match the Resource name listed in the Resource Name field of the TImeslip.  I can't determine why it's not.

trigger UpdateTimeSlip on TimeSlip__c (before insert, before update){
    Map<Id,Id> caseResourceMap = new Map<Id,Id>();
    String userId = userInfo.getUserId();
    String userName = userInfo.getName();
    Set<Id> caseIds = new Set<Id>();
   
    for(TimeSlip__c ts : trigger.new){
        caseIds.add(ts.Case__c);
    }
    for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){caseResourceMap.put(caseResource.Case__c,caseResource.Id);  
    }
      
    List<Contact> contactList = [select id,Name from Contact where Name =: userName];
    System.debug('contactList '+contactList );

    for(TimeSlip__c ts : trigger.new){
        if(ts.Resource_Name__c == null){
            if(contactList[0].Id != null){
                ts.Resource_Name__c = contactList[0].Id;
            }
        }
            if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
            }
    }
}
Here's my code.  Getting the following error: "Compile Error: Variable does not exist: ts.case_id @ line 9 column 79.  That is the correct field.  Any help would be greatly appriciated.

trigger UpdateCaseBillableAmount on TimeSlip__c (after insert, after update) {
     Integer rollUpAmount;
     for(TimeSlip__c ts : Trigger.New){
          if(ts.Billable_Amount__c != Null){
               rollUpAmount += ts.Billable_Amount__c;     //Suppose you want to add all in Rollup logic
          }
     }
     if(rollUpAmount != Null){
          Case c = [select id, total_billable_amount__c from case where id =: ts.case_id];
          c.total_billable_amount__c = rollUpAmount;
          update c;
     }
}

  • September 18, 2014
  • Like
  • 0
I believe I've ran into a limitation in SF, in that I cannot create a roll up summary on a cross object formula field.  Here's my scenario:

We have a custom Object: TimeSlip__c, which contains a field "Billable_Amount__c" that is a cross object formula.  It take the "Rate__c" from another related object (Case_Resource__c) and multiplies it by the number of hours entered on the TimeSlip (Total_Billable_Time__c).  

I'm trying to create a rollup summary on the Case Page that calculates the toal Billable Amount from all timeslips by rolling up the "Billable_Amount__c" field, but SalesForce isn't giving me this option.

I've been told I can achieve this with a trigger, and need some help writing the Apex Code.
  • September 17, 2014
  • Like
  • 0
I'd like to create an Apex Class that finds any 'Case_Resource__c' (Custom Object) where the following critera are met ont his object:
UOM__c = 'mo.'
Active__c = 'true'
For all Case_Resource__c records that are found matching those criteria, I'd like to create a new 'TimeSlip__c' (Custom Object) record.

The new TimeSlip__c record should map some data points from the Case_Resource__c record:
(Case Resource) Case__c should be mapped to the new (TimeSlip) Case__c
Case_Resource_ID should be mapped to the new (TimeSlip) Case_Resource_ID__c

The new TimeSlip__c record should also be created with this static value:
(TimeSlip) Total_Time__c = '1'

The result should be all Case_Resource__c records that are active and uom = mo. would then have a corresponding TimeSlip containing the matching Case, Case Resource ID, and a value of 1 in the Total Time field.

  • September 11, 2014
  • Like
  • 0
We have a custom object called "Case_Resource__c".

Is there a way to have a trigger run on a monthly basis (say the first of every month) as long as the following critera are true for the Case_Resource__c record:
1. UOM__c = "mo."
2. Active__c = true

And if so, to have that trigger create a new record for a different custom Object "TimeSlip__c" using fields from the Case_Resource__c object?

Again, looking for this trigger to fire automatcially every month and create a new "TimeSlip" so long as the "Case Resource" record has a UOM of "mo.", and is checked active.
  • September 11, 2014
  • Like
  • 0
trigger UpdateTimeSlip on TimeSlip__c (before insert, before update){
    Map<Id,Id> caseResourceMap = new Map<Id,Id>();
    String userId = userInfo.getUserId();
    String userName = userInfo.getName();
    Set<Id> caseIds = new Set<Id>();
   
    for(TimeSlip__c ts : trigger.new){
        caseIds.add(ts.Case__c);
    }
    for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
        caseResourceMap.put(caseResource.Case__c,caseResource.Id);  
    }
      
    List<Contact> contactList = [select id,Name from Contact where Name =: userName];
    System.debug('contactList '+contactList );

    for(TimeSlip__c ts : trigger.new){
        if(ts.Resource_Name__c == null){
            if(contactList[0].Id != null){
                ts.Resource_Name__c = contactList[0].Id;
            }
        }
        if(ts.Case_Resource_ID__c == null){
            if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
                ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
            }
        }
    }
}
I have the following Apex Trigger that is updating two fields on a custom object when saved.   The Case_Resource_ID__c field is being updated perfectly fine, but the Resource_Name__c field is not populating.  Here's the trigger:

trigger UpdateTimeSlip on Time_Slip__c (before insert, before update){
    Map<Id,Id> caseResourceMap = new Map<Id,Id>();
    String userId = userInfo.getUserId();
    String userName = userInfo.getName();
    Set<Id> caseIds = new Set<Id>();
   
    for(Time_Slip__c ts : trigger.new){
        caseIds.add(ts.Case__c);
    }
    for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
        caseResourceMap.put(caseResource.Case__c,caseResource.Id);  
    }
      
    List<Contact> contactList = [select id,Name from Contact where Name =: userId];

    for(Time_Slip__c ts : trigger.new){
        if(ts.Resource_Name__c != null){
            if(contactList[0].Id != null){
                ts.Resource_Name__c = contactList[0].Id;
            }
        }
        if(ts.Case_Resource_ID__c == null){
            if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
                ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
            }
        }
    }
}

We have a custom object 'TimeSlip' that I need to have a couple fields auto-populated via trigger if they are left blank when a new 'TimeSlip' is saved.  The first is a lookup field to the Contact object.  The second is a lookup field to another custom object.

The two fields I need to auto populate are:
Resource_Name__c - Lookup(Contact) field that, if blank, should auto populate with the current user name {!User.Name} on save.
Case_Resource_ID__c - Lookup(Case Resource) field that, if blank, should auto populate with the Case Resource ID, where {!User.Name} matches the Case Resource Name, on save.

Any help would be greatly appriciated!

 

New to this.  Wrote a working apex trigger, but no idea how to write test cases for it?

Here's the trigger code:
trigger CaseResource_CaseTeamMemberCreation on Case_Resource__c (after insert) {
    CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Case Member'];
    List<CaseTeamMember> members = new List<CaseTeamMember>();
  
    for (Case_Resource__c resource: Trigger.new) {
        if (resource.Resource_Name__c != null && resource.Case__c != null) {
            members.add(new CaseTeamMember(
                ParentID = resource.Case__c,
                MemberID = resource.Resource_Name__c,
                TeamRoleID = role.Id

           ));
        }
    }
  
    if (!members.isEmpty()) {
        insert members;
    }
We have a custom object "Case Resource" that allows us to build a table of resources with applicable bill rates on any given case.  We also use the Case Team object to control access to community users on a case by case basis.  I'd like to create either a workflow or trigger (not sure which is applicable), to automatically add a user to the case team, when they are manually added to the custom object as a case resource.  I need help writing the code on either the workflow or trigger if either could get the job done.
We have a custom object "Task_Custom__c" that I would like to add a button to.  When the button is clicked, we need two fields on this object to be updated:

Completion_Stats__c = "Completed"
Completion_Percentage__c = "100"

Can that be done with on click javascript?
I have the following trigger that adds a member to the case team, whenever a custom object "Case_Resource__c" is added to the Case.  The only problem is, the Resource_Name__c on the Case_Resource__c is a lookup value of the Contact object.  So when the Trigger creates a case team memeber, it is created as a Contact.  I want it to be created as a User, or Partner User.

Is there a way to update this code so that the Case Team Memeber Added is for the UserId (or Name...not sure which one) that matches the Contact Name?

trigger CaseResource_CaseTeamMemberCreation on Case_Resource__c (after insert) {
    CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Team Member'];
    List<CaseTeamMember> members = new List<CaseTeamMember>();
   
    for (Case_Resource__c resource: Trigger.new) {
        if (resource.Resource_Name__c != null && resource.Case__c != null) {
            members.add(new CaseTeamMember(
                ParentID = resource.Case__c,
                MemberID = resource.Resource_Name__c,
                TeamRoleID = role.Id

           ));
        }
    }
   
    if (!members.isEmpty()) {
        insert members;
    }
   

}
Here's my code.  Getting the following error: "Compile Error: Variable does not exist: ts.case_id @ line 9 column 79.  That is the correct field.  Any help would be greatly appriciated.

trigger UpdateCaseBillableAmount on TimeSlip__c (after insert, after update) {
     Integer rollUpAmount;
     for(TimeSlip__c ts : Trigger.New){
          if(ts.Billable_Amount__c != Null){
               rollUpAmount += ts.Billable_Amount__c;     //Suppose you want to add all in Rollup logic
          }
     }
     if(rollUpAmount != Null){
          Case c = [select id, total_billable_amount__c from case where id =: ts.case_id];
          c.total_billable_amount__c = rollUpAmount;
          update c;
     }
}

  • September 18, 2014
  • Like
  • 0
I believe I've ran into a limitation in SF, in that I cannot create a roll up summary on a cross object formula field.  Here's my scenario:

We have a custom Object: TimeSlip__c, which contains a field "Billable_Amount__c" that is a cross object formula.  It take the "Rate__c" from another related object (Case_Resource__c) and multiplies it by the number of hours entered on the TimeSlip (Total_Billable_Time__c).  

I'm trying to create a rollup summary on the Case Page that calculates the toal Billable Amount from all timeslips by rolling up the "Billable_Amount__c" field, but SalesForce isn't giving me this option.

I've been told I can achieve this with a trigger, and need some help writing the Apex Code.
  • September 17, 2014
  • Like
  • 0
I'd like to create an Apex Class that finds any 'Case_Resource__c' (Custom Object) where the following critera are met ont his object:
UOM__c = 'mo.'
Active__c = 'true'
For all Case_Resource__c records that are found matching those criteria, I'd like to create a new 'TimeSlip__c' (Custom Object) record.

The new TimeSlip__c record should map some data points from the Case_Resource__c record:
(Case Resource) Case__c should be mapped to the new (TimeSlip) Case__c
Case_Resource_ID should be mapped to the new (TimeSlip) Case_Resource_ID__c

The new TimeSlip__c record should also be created with this static value:
(TimeSlip) Total_Time__c = '1'

The result should be all Case_Resource__c records that are active and uom = mo. would then have a corresponding TimeSlip containing the matching Case, Case Resource ID, and a value of 1 in the Total Time field.

  • September 11, 2014
  • Like
  • 0
trigger UpdateTimeSlip on TimeSlip__c (before insert, before update){
    Map<Id,Id> caseResourceMap = new Map<Id,Id>();
    String userId = userInfo.getUserId();
    String userName = userInfo.getName();
    Set<Id> caseIds = new Set<Id>();
   
    for(TimeSlip__c ts : trigger.new){
        caseIds.add(ts.Case__c);
    }
    for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
        caseResourceMap.put(caseResource.Case__c,caseResource.Id);  
    }
      
    List<Contact> contactList = [select id,Name from Contact where Name =: userName];
    System.debug('contactList '+contactList );

    for(TimeSlip__c ts : trigger.new){
        if(ts.Resource_Name__c == null){
            if(contactList[0].Id != null){
                ts.Resource_Name__c = contactList[0].Id;
            }
        }
        if(ts.Case_Resource_ID__c == null){
            if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
                ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
            }
        }
    }
}
I have the following Apex Trigger that is updating two fields on a custom object when saved.   The Case_Resource_ID__c field is being updated perfectly fine, but the Resource_Name__c field is not populating.  Here's the trigger:

trigger UpdateTimeSlip on Time_Slip__c (before insert, before update){
    Map<Id,Id> caseResourceMap = new Map<Id,Id>();
    String userId = userInfo.getUserId();
    String userName = userInfo.getName();
    Set<Id> caseIds = new Set<Id>();
   
    for(Time_Slip__c ts : trigger.new){
        caseIds.add(ts.Case__c);
    }
    for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
        caseResourceMap.put(caseResource.Case__c,caseResource.Id);  
    }
      
    List<Contact> contactList = [select id,Name from Contact where Name =: userId];

    for(Time_Slip__c ts : trigger.new){
        if(ts.Resource_Name__c != null){
            if(contactList[0].Id != null){
                ts.Resource_Name__c = contactList[0].Id;
            }
        }
        if(ts.Case_Resource_ID__c == null){
            if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
                ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
            }
        }
    }
}

We have a custom object 'TimeSlip' that I need to have a couple fields auto-populated via trigger if they are left blank when a new 'TimeSlip' is saved.  The first is a lookup field to the Contact object.  The second is a lookup field to another custom object.

The two fields I need to auto populate are:
Resource_Name__c - Lookup(Contact) field that, if blank, should auto populate with the current user name {!User.Name} on save.
Case_Resource_ID__c - Lookup(Case Resource) field that, if blank, should auto populate with the Case Resource ID, where {!User.Name} matches the Case Resource Name, on save.

Any help would be greatly appriciated!