• MBrady325
  • NEWBIE
  • 0 Points
  • Member since 2010

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

I have two custom objects, one of which points to another via a lookup field, and I want to create a validation rule to ensure that when one record of the second object type is pointed to in said field, another will be unable to point to that same record.  That is, if Object1 has a lookup field called "Object2Lookup", and if Record A of type Object1 points to Record X of  type Object2 through that record's Object2Lookup field, I want to make sure that Record B of type Object1 gets an error if it tries to point to Record X in its Object2Lookup field.  How can I create a validation rule (or lookup filter) to do this?

I'm trying to create a custom button that will auto-select the From address when sending an email from a case, depending on a custom field on the case record.  I've tried several ways of doing this, but none of them seem to be working correctly.  One of the posts I found on the board uses Javascript to hack the URL, and I've tried doing this, but I get the error "unexpected token ILLEGAL" when I try it.  Here's the code I'm using:

 

IF({!Case.CustomField__c} = 'Option 1', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address1@gmail.com;, 

(IF({!Case.CustomField__c}='Option 2', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address2@gmail.com;, 

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId};)))

 

I imagine I'm doing this wrong, since this seems to be mixing Salesforce formulas with Javascript.  Is this the correct way to approach my issue, or is there a way to make the button link to the desired URL without using Javascript?

I use a custom object called vftimer to log hours, and it is part of a managed object, so I'm unable to make it part of a master-child relationship and use roll-up summaries.  When a vftimer object (Timed Item) is created with an amount of time in the Time field, it is associated with a case, and there is a custom field on the case for Total Hours Logged.  I want the Total Hours Logged field to be updated by adding the amount of the Time in the Timed Item object to the total.  Here's what I think I need to do:

 

trigger add_time_to_total on vftimer__TimedItem__c (after insert) { 

for (vftimer__TimedItem__c t : trigger.new){

ID case_ID = t.vftimer__Case__c;

case timer_case = [select id,Total_Hours_Logged__c from case where id = :case_ID limit 1];

timer_case.Total_Hours_Logged__c += t.vftimer__Time__c;

upsert timer_case;

}

}

 

When I try to create a new Timed Item, I get this error:

 

Apex trigger add_time_to_total caused an unexpected exception, contact your administrator: add_time_to_total: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.add_time_to_total: line 4, column 19

 

I'm obviously doing something wrong here; is the SOQL query incorrect?  Is there a better way to look up the case that is associated with the Timed Item and update it?

I'm new to Apex coding, so I have what is probably a really simple question about getting a trigger to update a field.  I have a custom object called Timed Item that relates to a case, so I want to be able to have a case field that shows the total of all Timed Items in a case's related list.  I figure the way to do this is create a trigger that fires after insert of the timed item, taking the amount of the Time field from the newly-created Timed Item and updating the Total Hours field of the case by adding the amount of the Time field to the total.  I think I have to do something like this, but I'm not sure:

 

 

trigger add_time_to_total on vftimer__TimedItem__c (after insert) {

 

vftimer__TimedItem__c time = ???

Case c = time.vftimer__Case__c

c.Total_Hours_Logged__c += time.vftimer__Time__c

insert c

}

 

What do I need to put into the ??? to make the "time" object grab the data from the Timed Item which was just created?  And do I have everything else correct, updating the Total Hours Logged field with the amount of the Timed Item?

 

Thanks for the help, anybody that bothers to respond!

I have two custom objects, one of which points to another via a lookup field, and I want to create a validation rule to ensure that when one record of the second object type is pointed to in said field, another will be unable to point to that same record.  That is, if Object1 has a lookup field called "Object2Lookup", and if Record A of type Object1 points to Record X of  type Object2 through that record's Object2Lookup field, I want to make sure that Record B of type Object1 gets an error if it tries to point to Record X in its Object2Lookup field.  How can I create a validation rule (or lookup filter) to do this?

I'm trying to create a custom button that will auto-select the From address when sending an email from a case, depending on a custom field on the case record.  I've tried several ways of doing this, but none of them seem to be working correctly.  One of the posts I found on the board uses Javascript to hack the URL, and I've tried doing this, but I get the error "unexpected token ILLEGAL" when I try it.  Here's the code I'm using:

 

IF({!Case.CustomField__c} = 'Option 1', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address1@gmail.com;, 

(IF({!Case.CustomField__c}='Option 2', location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&p26=address2@gmail.com;, 

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId};)))

 

I imagine I'm doing this wrong, since this seems to be mixing Salesforce formulas with Javascript.  Is this the correct way to approach my issue, or is there a way to make the button link to the desired URL without using Javascript?

I use a custom object called vftimer to log hours, and it is part of a managed object, so I'm unable to make it part of a master-child relationship and use roll-up summaries.  When a vftimer object (Timed Item) is created with an amount of time in the Time field, it is associated with a case, and there is a custom field on the case for Total Hours Logged.  I want the Total Hours Logged field to be updated by adding the amount of the Time in the Timed Item object to the total.  Here's what I think I need to do:

 

trigger add_time_to_total on vftimer__TimedItem__c (after insert) { 

for (vftimer__TimedItem__c t : trigger.new){

ID case_ID = t.vftimer__Case__c;

case timer_case = [select id,Total_Hours_Logged__c from case where id = :case_ID limit 1];

timer_case.Total_Hours_Logged__c += t.vftimer__Time__c;

upsert timer_case;

}

}

 

When I try to create a new Timed Item, I get this error:

 

Apex trigger add_time_to_total caused an unexpected exception, contact your administrator: add_time_to_total: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.add_time_to_total: line 4, column 19

 

I'm obviously doing something wrong here; is the SOQL query incorrect?  Is there a better way to look up the case that is associated with the Timed Item and update it?

I'm new to Apex coding, so I have what is probably a really simple question about getting a trigger to update a field.  I have a custom object called Timed Item that relates to a case, so I want to be able to have a case field that shows the total of all Timed Items in a case's related list.  I figure the way to do this is create a trigger that fires after insert of the timed item, taking the amount of the Time field from the newly-created Timed Item and updating the Total Hours field of the case by adding the amount of the Time field to the total.  I think I have to do something like this, but I'm not sure:

 

 

trigger add_time_to_total on vftimer__TimedItem__c (after insert) {

 

vftimer__TimedItem__c time = ???

Case c = time.vftimer__Case__c

c.Total_Hours_Logged__c += time.vftimer__Time__c

insert c

}

 

What do I need to put into the ??? to make the "time" object grab the data from the Timed Item which was just created?  And do I have everything else correct, updating the Total Hours Logged field with the amount of the Timed Item?

 

Thanks for the help, anybody that bothers to respond!