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
Rocks_SFDCRocks_SFDC 

How to Pre - Populate the Name field for custom object in visual force page

Hi Team,

I would like to set the value for the name field for custom object in visual force page when we click on the "New" button. I just want to pre-populate the value to "Some Text". Can anyone help me out ?

Thanks,
Anil
Best Answer chosen by Rocks_SFDC
Abhishek BansalAbhishek Bansal
Hi ,

Please use the below syntax to auto-pouplate Name field for any custom object.
<apex:page standardController="Campsite__c" action="{!URLFOR($Action.Campsite__c.New, null, ['Name'='Test Name'], true)}">

//Replace Campsite__c with your custom object API name.

Le me know if you need more help on this.

All Answers

Abhishek BansalAbhishek Bansal
Hi ,

Please use the below syntax to auto-pouplate Name field for any custom object.
<apex:page standardController="Campsite__c" action="{!URLFOR($Action.Campsite__c.New, null, ['Name'='Test Name'], true)}">

//Replace Campsite__c with your custom object API name.

Le me know if you need more help on this.
This was selected as the best answer
Rocks_SFDCRocks_SFDC
Thank you Abhishek for your response. It worked well.

And also we want to append "some text" lets say "Copy" to the Name field of a custom object when we click on "Clone" button.

Do we have any workaround for this.

Thanks in Advance,
Anil
Abhishek BansalAbhishek Bansal
Hi Anil,

The clone parameter is not available on URLfor function.
Clone button by default populates the value from a record on which your are clicking clone So if you want to populate different values other than the current record than you have to create a Custom VF page and in its controller you can change the values of field and than Overide your Clone button with this VF page.

There is no way to do it directly as we have done for New.
Let me know if you need more clarification or help on this.

Regards,
Abhishek.
Rocks_SFDCRocks_SFDC
Thanks Abhishek,

if you send me some sample VF page and Controller code to achieve the functionality, then that could be great helpful.

Thanks,
Anil
Abhishek BansalAbhishek Bansal
Hi Anil,

If your original question has been solved than please mark it as SOLVED and it would be good to post you post your new question in another forum so that different questions do no mix up in the single forum.
Posting the new question in another forum will be helpful for everyone to find different solution of different question on different forums and it will alos avoids confusion.
So pelase make a new question of your current request and send me the link here, I will definitely reach you out there and provide you all the possible help.

Thanks,
Abhishek.
 
Rocks_SFDCRocks_SFDC
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BXryIAG