+ Start a Discussion
Rogerio Lara 2028Rogerio Lara 2028 

Pre-Populate field "name"

Hi there,  I have a new custom object Opportunity Positioning, that is related to the Opportunity object.

I need the field  "Opportunity Positioning" which is a name field when the object was created,  to be populated with a default value "Autofill" at insert.

I've tried to override the New button on the  Opportunity Positioning related list to the Opportunity, and it works, however the relation between the Opportunity and the Opportunity Positioning objects disappears and it has be manually selected again.

<apex:page standardController="Opportunity_Positioning__c" action="{!URLFOR($Action.Opportunity_Positioning__c.New, null, ['Name'='Autofill'], true)}" />

Any ideas how I can retain the relationship between objects when creating a new record and at the same time update the Opportunity Positing field? Thank you.
Nayana KNayana K
Can you please post whole code of Page? Do you have any extension code?
GauravGargGauravGarg
Hi Rogerio,

Please use Lookup / Master-detail relationship based on your requirement i.e.
Lookup: Loosely coupled record, i.e. on deletion of parent record, child record will exist in the system.
Master-Detail: Tightly coupled record, On deletion of Parent record, child record will also be deleted. 

Create new field Parent Opportunity on Opportunity Positioning object and populate it at the time of creation with Opportunity object id. 
This way, there will be a relation always. 

To update Opportunity Positioning field with default values. Salesforce provide default value option at the time of field creation and edit. 

Please follow below steps:
Go To Opportunity Object.
Search for Opportunity Positioning field.
Edit this field.
In the "General Options" section, enter values in "default value" section.

Hope this will helps you, Let me know if you need more assistance on this. 

Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990