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
Akshay KapadiaAkshay Kapadia 

How can I create new record for custom object from visual force page on custom button click?

Hi guys, I'm totally new to salesforce, just started. I need your help in, how can I create new record of custom obejct from visualforce page by clicking on custom button?

So I've one custom object called; 'project' and  other 'mapview' and i got visualforce page attached to mapview object and in that page i have custom button, on that button click i want to create new project record. I've gone through few solutions but couldn't understand. 

So posting here and asking for help.

here is what I'm doing:

<apex:page standardController="MapView__c" wizard="true"  >
    
    <apex:pageBlock >
        <apex:form >
                   <apex:commandButton id="btnCreateProject" action="{!URLFOR($Action.MapView__c.Create_New_Project)}" value="Create a project"/>

        </apex:form>
    </apex:pageBlock>
    
</apex:page>
Best Answer chosen by Akshay Kapadia
SaiGSaiG
Akshay, Try this sample below:

<apex:page standardController="MapView__c" wizard="true"  >
<apex:form>
<apex:pageBlock>
        <apex:pageBlockButtons>
             <apex:commandButton action="{!URLFOR($Action.<ObjectName>.New)}"  Value="Create a Project"/>
        </apex:pageBlockButtons>


    </apex:pageBlock>
        </apex:form>    
</apex:page>

Thanks,
Sai

All Answers

SaiGSaiG
Akshay, Try this sample below:

<apex:page standardController="MapView__c" wizard="true"  >
<apex:form>
<apex:pageBlock>
        <apex:pageBlockButtons>
             <apex:commandButton action="{!URLFOR($Action.<ObjectName>.New)}"  Value="Create a Project"/>
        </apex:pageBlockButtons>


    </apex:pageBlock>
        </apex:form>    
</apex:page>

Thanks,
Sai
This was selected as the best answer
Akshay KapadiaAkshay Kapadia
Thanks Sai Garnepudi. that is what i wanted. thanks a lot. One more question, what if I want to implement some logic in the background before creating new project?

Do i need to use controller? 

appreciate your time.
thanks
SaiGSaiG
Yes using a controller is a better option. If it is simple logic like making a field required, you can do that on the VF tags (rendered, required, etc).
Akshay KapadiaAkshay Kapadia
thanks Sai Garnepudi. Sorry but could you please help me how can i save some values into other obejcts and populate create new project pop up with few fields already preloaded values using controller?

Thanks.