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
Jagmohan Singh 8Jagmohan Singh 8 

Create new record from an existing record page

Is it possible to create a new record when you're on an existing record. For example: When you're viewing a contact or oppotunity, is it possible to create a new record from the same page? 

I could not find a 'New' button in the page layout. Basically I would like to have a 'New' button next to Edit, Delte, Clone. Is this possible?

Thanks in advance
Create new record
Best Answer chosen by Jagmohan Singh 8
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Jagmohan,

This functionality can be done creating a custom 'New' Button and the standard button cannot be used in this case.

So create a 'New' detail page button on teh required object and pass the url as: window.open("/001/e");  --- 001 is the object code (This is for Account object).

Add the button to the page layout and this works as expected.

Thanks
Hope this will be helpful.

All Answers

Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Jagmohan,

This functionality can be done creating a custom 'New' Button and the standard button cannot be used in this case.

So create a 'New' detail page button on teh required object and pass the url as: window.open("/001/e");  --- 001 is the object code (This is for Account object).

Add the button to the page layout and this works as expected.

Thanks
Hope this will be helpful.
This was selected as the best answer
Ahmed Ansari 13Ahmed Ansari 13
Hii Jag Mohan 

As workaround that you create VF Page as given below and after that you create a Detail Page Button with URL  
Step 1:
VF page Name : "AddAccount"
 
<apex:page controller="AddAccountController" tabStyle="Account" showHeader="false" sidebar="false">
    <apex:form >
        <apex:pageBlock title="Add Account" mode="edit">
            <apex:pageBlockButtons>                   
                <apex:commandButton value="Save" action="{!save}"  />
                <apex:commandButton value="Cancel" action="{!cancel}" />
            </apex:pageBlockButtons>  
            <apex:pageBlockSection title="Account Details" columns="2">            
                <apex:inputField value="{!act.name}" /> 
                <apex:inputField value="{!act.site}"/> 
                <apex:inputField value="{!act.type}"/> 
                <apex:inputField value="{!act.accountNumber}"/>              
            </apex:pageBlockSection>          
                   
        </apex:pageBlock>
    </apex:form>
</apex:page>



Controller name : "AddAccountController"
public class AddAccountController {
    public Account act{get;set;}
    public AddAccountController() {       
        act = new Account();
    }
    
    public PageReference cancel() {
        return null;
    }
    
    public PageReference save() {
        insert act;
        return new PageReference('/'+act.id);
    }
}

Step 2:

Detail Page Button
Name : New Account
URL : / apex/AddAccount

Step 3: 


Add Newly created buuton on edit layout

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Regards,
Ahmed Ansari



 
Ahmed Ansari 13Ahmed Ansari 13
Hi Jag Mohan
do one more thing for above vf page Show header  and sidebar value is "true"
 
Jagmohan Singh 8Jagmohan Singh 8

Thanks for the quick replies guys.
I choose the method that Bhargavi suggested (because it sounded easier) and it works