I have a custom field called Contact__c in my Opportunity object. It is a lookup to the Contact object. I created a custom button to send email so I could edit the URL to fill in the TO: field with Contact__c. The custom button has the following in it:


This is not working because it's putting the the name in the url instead of the Contact Id. Example:


If I edit the URL manually in my browser and change "Randy+Riegel" to the ID of that contact the field populates fine when refreshed. How can I get the ID in the URL instead of the Name?

  • 3
    Have you tried {!Opportunity.Contact__r.Id}? – sfdcfox Jan 12 '15 at 16:49
  • If I put that in the URL it will not let me save the button. It says {!Opportunity.Contact__r.Id} does not exist. – Randy R Jan 12 '15 at 17:40
  • Try creating a custom Text formula field in Opportunity called ContactId__c that is defined as Contact__r.id. Then reference {!ContactId__c} in the URL construction – cropredy Jan 12 '15 at 18:53
  • But what if there is more than one contact? Somehow I need to reference the custom field that has the "Primary Contact" in it. – Randy R Jan 12 '15 at 22:31
  • if there is more than one contact, you are presumably talking about the members of the OpportunityContactRole sobject? and you want to send an email to the primary OCR? – cropredy Jan 13 '15 at 1:56

If It was standard field you could have directly used the merge fields and put {!Contact.Id}


But in your case, below approach will work.

So essentially what I did was created a custom field on Opportunity called as 'Primary_Sales_Contact__c' and I tried to open the below URL that worked like a charm.

/_ui/core/email/author/EmailAuthor?p2_lkid={! Opportunity.Primary_Sales_ContactId__c}
| improve this answer | |
  • Hah, funny. I answered that and deleted it cause the OP said they were using a custom field Contact__c. – Eric Jan 12 '15 at 18:50
  • In your 'Primary_Sales_Contact_c' did you reference a custom field? If you are referencing the contact object what would happen if there are more than one? Don't I somehow have to reference "Contact__c"? – Randy R Jan 12 '15 at 22:41
  • yes, this is a custom field. As this field is on Opportunity Object, it will always have a single Contact. How can you have more than one ? Do you have any such scenario? where is your 'Send Email'button positioned? – Amit Bangad Jan 13 '15 at 6:53
  • My send email button is at the top of the screen in the row of buttons that have Edit/Delete/Clone etc. Does this make a difference? Just now getting a change to work on this today. Had to put out some other fires earlier – Randy R Jan 13 '15 at 17:00
  • I created a text formula field that pointed to my other custom field. Everything is working great now. – Randy R Jan 13 '15 at 19:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.