function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kfrankfran 

How do I get a custom field to automatically pre-populate?

Hello,
 
I've created a custome "email field" in Opportunities>  How do I get the email faddress rom the Contact page to pre-populate in my custom email field in Opportunities?  Do I use the S-Control for that?
 
My ultimate goal is to create an Opportunity View which includes email addresses.  When I go to create an Opportunity view, email is not an available field to display.
 
Please help!
 
Thanks.
jrotensteinjrotenstein
Several options:

Trigger to copy field
You could write an APEX Trigger that fires when the Opportunity is created, which copies Email from the Contact. However, if the Contact's email address changes in future, this will not be copied down to the Opportunity. (Unless you write another Trigger.)

S-Control to display, but not store, value
You could put an in-line S-Control on the Opportunity page that displays {!Contact.Email}. This will not be editable, and will always show the correct Email value on the Contact.

Something else
You could modify the "New Opportunity" functionality to pre-populate a field with a value from the Contact, but it's a bit more messy than the above. Oh, and with the Summer '08 edition about to come out, you could reference the field directly via a formula (it seems).
kfrankfran

Thanks for your response, but what do you mean by an "in-line" S-Control?

Would I still need the actual S-Control 'Code' which will allow me to copy emails from contacts and transfer populate in the Opportunity page?

 

Thanks so much.  This is all very new to me.

jrotensteinjrotenstein
If your "ultimate goal" is to have the email field showing on the Opportunity page, the S-Control can display this without actually having to create a field.

Do you have any particular need to store the email on the Opportunity record itself? (eg to show it in lists or in a Console column)
kfrankfran
Yes, this is exactly what I want to do.  I want to be able to see the contact email on the Opportunity Custom View List which is why I need to have the email field on the Opportunity page. 
 
I go to create the S-Control, but I must be doing something wrong because it's not working.  How do I create the S-Control to do this?
 
Thanks so much.
jrotensteinjrotenstein
Ah! I just realised that there is no Contact field on an Opportunity. It links to Account, but not Opportunity.

So, the first question is... what Contact's email address do you wish to show?

If you have added a custom Lookup(Contact) field on Opportunity, then the code would be something like:

Code:
<html> 
<head> 
<script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script> 
</head> 
<body bgcolor=#f3f3ec>

<script>
var contacts = sforce.connection.query(
"select Email from Contact where Id = '{!Opportunity.Custom_ContactId__c}'"); records = contacts.getArray("records"); document.write(records[0].Email); </script>

</body> </html>

 Put the S-Control on your Opportunity Page Layout, turn on "show label", make the height about 20 and it should appear!

It would be much easier to show the Account's Email address. You'd just have to put in {!Account.PersonEmail}


Message Edited by jrotenstein on 05-23-2008 03:52 PM
kfrankfran

Hello,

 

I wish to show all my contact emails on Opportunities.  Is this possible?  I have not added a Custom lookup field in Opportunity.  Let me try this.  Thanks so much.

CventCvent
I have tried to customize this code to update few fields in a custom object. but everytime it doesn't show me any result.
 
Here is the code that i implemented:
 
<html>
<head>
<script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script>
</head>
<body bgcolor=#f3f3ec>
<script>
var Accounts = sforce.connection.query( "select Metro_Area from Account where Id = '{!RFP__c.Supplier_AccountId__c}' ");
records = Accounts.getArray("records");
document.write(records[0].Metro_Area);
</script></body>
</html>
 
I kept type as HTML; "RFP" is a custom object in which i want to update custom field named "Metro Area"
jrotensteinjrotenstein

Hi Cvent,

What do you mean by "update a few fields"? Do you want to change the value of fields within the Salesforce database, or do you just want to show the text on the screen?

The code you have listed would only show information on the screen -- there is nothing there to update any fields.

Also, you will probably hav to change {!RFP__c.Supplier_AccountId__c} to {!RFP__r.Supplier_AccountId__c} but I'm not sure how your schema is organised.

CventCvent

Basically i have added a custom object in SF and i have linked account under master relationship, now i would like to display certain fields from the account level under the custom object without manually rentering them.

Either i wait till cross object formulas are launced, or if i could display these fields in the new object via custom s control...

Since i saw your post i though it could work, though my display came as blank; I tried to use the code that you gave below it didnt work. I have no idea about about Java or coding of any sought though we have tried our hand on similar things before though difficulty level would be a .5 on a scale of 100. Any help would be appreciated...

WhyserWhyser
I know this is more of a manual process, but you can add Contact Roles to an Opportunity.
 
A Contact Role is basically a Contact from the Account that is related to the Opportunity. When these are filled out, you can see their email and other related information as a related list.
 
The reason why you may want to go down this route is because if an Account is very large (and has perhaps over 30+ contacts), you probably won't need to see ALL of them on the Opportunity level, only the ones that are directly related to the Opportunity.
 
But like I said, this is a more manual process, you will have to "add" them into the opportunity. It's not the best solution, but it may be a possible alternative. Or you can look into having an s-control that will create all the contact roles for you when the opportunity is created.