I have a master-detail record that works like this: Contact > ContactEmail > Email (based on this many-to-many document: https://help.salesforce.com/apex/HTViewHelpDoc?id=relationships_manytomany.htm&language=en_US). So a contact could have multiple email records, and they're created via the ContactEmail object.

This is all working fairly well, and I'm attempting to edit the page layouts to make them usable.

Currently, on the Contact layout I'm able to list the Email records associated with it. This works well. But I've been trying to edit the New button. Here's what I'd like to have happen:

  1. User clicks New Email Address button
  2. User is sent to New Email page, and adds a new Email record (this is currently working).
  3. Upon save on that Email record, user is sent to a ContactEmail entry page which has a prefilled Contact lookup value (this is currently working) and a prefilled Email lookup value (this is what I can't resolve).

So in this way, a user from the Contact page could add a new Email record and easily associate it via a ContactEmail record.

My button currently is setup like this:

  1. Label: New Email Address
  2. Name: New_Email_Address
  3. Display Type: List Button
  4. Behavior: Execute JavaScript
  5. Content Source: OnClick JavaScript

And here's the button's JavaScript (attempting to indent for legibility; it's all one line when saved):


I'm assuming the saveurl parameter is the key here. I've been trying various configurations of that parameter - url encoded, double url encoded, not encoded at all. I've been successful in getting the Contact lookup, but not the Email lookup.

Any ideas?

  • 1
    The Email__c record doesn't exist when your javascript is constructing the URL, so I don't think it can be populated that way. Would you consider an Apex trigger to do this? Also, can you explain why an email address is related to multiple Contacts? – Jeremy Nottingham Nov 6 '14 at 23:23
  • I finally realized that, though it took me forever! The reason for the relationship is this: a Contact could have multiple email addresses, and (in our case) it's also possible that a single email address could relate to multiple Contacts (for example in our case, an executive and her assistant, or spouses who share an email). Then the positive is that on the ContactEmail record itself, we could flag primary, type of address, etc. I'd certainly consider an Apex trigger, but I'm not sure how to handle redirects (so it could create a new ContactEmail record?) in that case. – Jonathan Stegall Nov 7 '14 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.