Sending email from custom object not populating Contact in To: field - Answers - Salesforce Trailblazer Community
Ask Search:
Brian BeckBrian Beck 

Sending email from custom object not populating Contact in To: field

Hi

I have a custom object (Membership) with a master-detail to Contacts and a number of look-up fileds relating to the Contact record.

If I am in the custom object (Membership) and try to send an email from Activity History, the Contact is not pre-populating. (If I try to send an email from the Contact record, the Contact is filled in but Membership field is blank as expected)

Is there any way to make the Contact pre populate the Contact field in the custom object?

See screenshot. 

User-added image

Best Answer chosen by Moderator (salesforce.com) 
Adam MarksAdam Marks
Go to edit your URL button and click on the Insert Field pick list. That is a list of all available fields you can drill into from the object. Make sure you have your Membership object choses as the Selected Field Type. Assuming you have a look up relationship between your Membership and Contact object you should see a field called Contact ID. Select it and it will populate the proper name of the field. If you don't see the listed there then you don't have the two objects related to each other.

See my screenshot. User-added image

All Answers

Adam MarksAdam Marks
Just a thought but I think the system needs to find an e-mail field on the object. That would be easy enough to test and if that works you could try creating a formula field that pulls in the email address from the contact (assuming the relationship is 1:1) and then creating a blank e-mail field that is updated via a Workflow Rule. It's kind of a long way to go I know, but if it works you only have to worry about it once!
Brian BeckBrian Beck

Thanks Adam,
I tried that but it doesn't seem to care whether there is a populated email field on the object.

B.

 

Adam MarksAdam Marks
Worth a shot. I did manage to get it working by creating a custom button using the following URL syntax

/_ui/core/email/author/EmailAuthor?p3_lkid=a08U0000005FNVT&p2_lkid={!Custom_Object__c.ContactId__c}&retURL=%2Fa08U0000005FNVT


You will need to adjust the {!Custom_Object} field to the name of your custom object as well as the name of the lookup relationship field depending on what you named it. 

This assumes you have a lookup relationship on your custom object to your Contacts object and that a user has created the relationship between the two. 

Name your button Send Email (or whatever tickles your fancy) and add it to your page layout. Scroll down to your Activity History related list and click the wrench at the top of its section. Expand the Buttons section and uncheck the Send an Email option. 

Now all your users should see is the custom button you created. 

Let me know if this works for you. It should, I just built it out real quick and tested. 
Brian BeckBrian Beck
Thanks Adam,
Unfortunately, it isn't working. I get an error -see below.

Unable to Access Page
The value of the "p3_lkid" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

salesforce.com/_ui/core/email/author/EmailAuthor?p3_lkid=a08U0000005FNVT&p2_lkid={!Membership__c.Membership_Contact__c}&retURL=%2Fa08U0000005FNVT

Adam MarksAdam Marks
p3_lkid is the object related to field. You will want to replace the record ID in my syntax to {!Your_Custom_Object__c.Id} obviously change that to the name of the object that you are sending the email from.

Sorry about that. It was end of my day and my brain misfired! 
Adam MarksAdam Marks
For the sake of clarity here is my actual URL. I used a test object called New Hires and tied it to my Contacts record. You will need to change the field references but the syntax is correct, tested and verified. 

/_ui/core/email/author/EmailAuthor?p3_lkid={!New_Hire__c.Id}&p2_lkid={!New_Hire__c.ContactId__c}&retURL=%2Fa08U0000005FNVT

the ret URL contains my record ID as well. You can edit that out or change it to another field reference if you want. 
Brian BeckBrian Beck

Adam, Thanks for your time and help.

I'm not really getting this I'm afraid. Apologies. It's still throwing the same error about p3_lkid.

This is what i have now:

/_ui/core/email/author/EmailAuthor?p3_lkid={!Membership__c.Id}&p2_lkid={!Membership__c.Membership_Contact__c}

Some notes:
Membership_Contact__c is the Contact name on the custom object Membership__c

I tried putting in a URL Id code for where you have .Id but that didn't work. I guess I'm not sure of the syntax etc. further assistance would be appreciated.

Thanks
 

Adam MarksAdam Marks
No need to apologize. Let's break the URL apart and hopefully that will get you to the solution: 

/_ui/core/email/author/EmailAuthor? (This specifies the email page and tells Salesforce to launch the "I want to send an email page. No modification necessary as far as I know.)

p3_lkid={!New_Hire__c.Id} (p3_lkid is the ID of the field as it appears in Salesforces HTML. Your reference here should the object.id of the object/record you are firing the email from. In my case I was sending it from an existing record on my New Hire object. If you are sending the email from your Membership object then you would use Membership__c.Id)

&p2_lkid={!New_Hire__c.ContactId__c} (& simply means "and". p2_lkid is the To field. You want to populate this with the related to ID for the record that has your email address. I believe to make this work you have to hook this to a standard object such as Lead or Contact. I didn't have another custom object to test with. In my example I hooked my New Hire object to the standard Contact's object. In your example, assuming your Membership is hooked to Contacts you would use Membership__c.ContactId__c. )

&retURL=%2F{!New_Hire__c.Id} (This is your return URL. This is optional but what this will do is tell the system what page to go back to after the page and been submitted. In my example I want it to go back to my New Hire record I sent the email from. In your example you can use your Membership__c.Id. 

So putting it all together with what I understand your objects/relationships to be it would look like this: 

/_ui/core/email/author/EmailAuthor?p3_lkid={!Membership__c.Id}&p2_lkid={!Membership__c.ContactId__c}&retURL=%2F{!Membership__c.Id}



Fingers and toes crossed that works for you. I probably should have done that from the start. 

Also, of note, don't be afraid to use the Insert Field look up when creating your URL. Sometimes things don't work because of small syntax issues and letting the system insert the proper values can save time. I do it, all the time. Worst case, use the lookup to pull your object values into the URL and then try it one more time. Assuming of course you still get an error. 


Brian BeckBrian Beck

 

/_ui/core/email/author/EmailAuthor?p3_lkid={!Membership__c.Id}&p2_lkid={!Membership__c.ContactId__c}&retURL=%2F{!Membership__c.Id}

 

I used this and it threw a syntax error saying ContactId__c could not be found.

We use the NPSP which doen't seem to have a custom field called ContactId__c. So I added another look-up to the custom object called Account and used AccountId__c. That threw no syntax errors. However a preview gave me the same error as before:

You are welcome to share my screen if feasible.

Sigh!

Unable to Access Page

The value of the "p3_lkid" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.
Adam MarksAdam Marks
Go to edit your URL button and click on the Insert Field pick list. That is a list of all available fields you can drill into from the object. Make sure you have your Membership object choses as the Selected Field Type. Assuming you have a look up relationship between your Membership and Contact object you should see a field called Contact ID. Select it and it will populate the proper name of the field. If you don't see the listed there then you don't have the two objects related to each other.

See my screenshot. User-added image
This was selected as the best answer
Brian BeckBrian Beck

Update:

Forget the preview. I added the button to the Membership object and I get the email poping up with this URL:

https://na7.salesforce.com/_ui/core/email/author/EmailAuthor?p3_lkid=a0iA0000004Qxxx&p2_lkid=001A000000pKxxx&retURL=%2Fa0iA0000004Qxxx

(xxx added to obfuscate)

All is there except the Contact info as before.

Adam MarksAdam Marks
Yes, sorry I should have specified. The button needs to live under the object you are sending the email from. 

Now that you have a workable URL you can back into the right syntax. That's all I did (see no magic involved.) Take your working URL, and then use the Insert Field options to build it out. You have the technology now. Better. Faster. Stronger. 
Brian BeckBrian Beck

Got it! Works great.

Thanks so much.

B.

Brian BeckBrian Beck

/_ui/core/email/author/EmailAuthor?p3_lkid={!Membership__c.Id}&p2_lkid={!Membership__c.Membership_ContactId__c}&retURL=%2F{!Membership__c.Id}

Final working version.

Adam MarksAdam Marks
Awesome. Glad it's all working now. 
Lone Star69Lone Star69
When you click on the cc and bcc lookups, the drop down allows you to select the users in the Org, is it possible to select the contacts in the Org here?

No luck finding info reg this...

Please let me know!