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
Raviteja KothaRaviteja Kotha 

linking vf page button to custom object record

question-User when clicks  "Launch" button in Account, VF page should be displayed with atleast 3-5  fields as input field  from account, and again when user clicks "submit" button in VF page all the data in those input fields should be  stored as an record in any  custom object.User-added image  
my status-I have created a launch button and linked it to vf page where i have made input fields from account now when ever i am clicking submit it is not going to my custom object..Please help me to sort out this scenario
Best Answer chosen by Raviteja Kotha
kalpeshs91kalpeshs91
// Controller
public class LaunchAccountController
{    
    public Account aObj{get; set;}
    
    public Pagereference Submit()
    {
        customObject__c cobj = new customObject__c();
        cObj.Name__c = aObj.Name;
        cObj.phone__c = aObj.Phone;
        cObj.Fax__c = aObj.Fax;
        insert cObj;
        
        //If you want to redirect page to new created record
        PageReference pageRef = new PageReference('/'+cObj.id);
        pageRef.setRedirect(true);
        return pageRef;
    }    
}

<apex:page controller="LaunchAccountController">
..
    <apex:inputField value="{!aObj.Name}"/>
    <apex:inputField value="{!aObj.Phone}"/>
    <apex:inputField value="{!aObj.Fax}"/>
    <apex:commandbutton value="Sumbit" action="{!Submit}"/>
..
</apex:page>

Mark as correct answer, if this you were expecting.. :)

-Kalpesh Surana
kalpeshsurana@live.com
+91 9028851237

All Answers

ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi Raviteja,

you need to redirect your page to that perticular page as you required.

on click of submit button you must have on controller method. make that method as "public pageredirect  " and give return value as below.

Pagereference ref =new Pagereference('/'+URL); //replace URL as you need 
return ref;

let me know, if it helps you or need any help :)

shiva.sfdc.backup@gmail.com
Raviteja KothaRaviteja Kotha
could you please solve it send me
Raviteja KothaRaviteja Kotha
i am new to sales force
 
kalpeshs91kalpeshs91
// Controller
public class LaunchAccountController
{    
    public Account aObj{get; set;}
    
    public Pagereference Submit()
    {
        customObject__c cobj = new customObject__c();
        cObj.Name__c = aObj.Name;
        cObj.phone__c = aObj.Phone;
        cObj.Fax__c = aObj.Fax;
        insert cObj;
        
        //If you want to redirect page to new created record
        PageReference pageRef = new PageReference('/'+cObj.id);
        pageRef.setRedirect(true);
        return pageRef;
    }    
}

<apex:page controller="LaunchAccountController">
..
    <apex:inputField value="{!aObj.Name}"/>
    <apex:inputField value="{!aObj.Phone}"/>
    <apex:inputField value="{!aObj.Fax}"/>
    <apex:commandbutton value="Sumbit" action="{!Submit}"/>
..
</apex:page>

Mark as correct answer, if this you were expecting.. :)

-Kalpesh Surana
kalpeshsurana@live.com
+91 9028851237
This was selected as the best answer
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi Raviteja,

Gimme your object names so that I can make snippet for you :)

shiva.sfdc.backup@gmail.com
Raviteja KothaRaviteja Kotha
hi shivakumar i have tried it but it is not redirecting
 
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi Raviteja,

 Controller
--------------------
public class SubmitClass
{    
    public Account acc{get; set;}
    
    public Pagereference Submit()
    {
        PageReference ref = null;
        YourObject obj =  new YourObject();
        //fill the data
        obj.Phone = acc.Phone;
        obj.Phone = acc.Jigsaw;
        obj.Phone = acc.ParentId;
        obj.Phone = acc.Type;
        try{
            insert Obj;
            ref = new PageReference('/'+Obj.id);
            ref.setRedirect(true);
        }catch(exception ex){
            system.debug('ERROR'+ex.message());
        }
        return null;
    }    
}

Page
----------- 
<apex:page Controller="SubmitClass">
   <apex:form >
      <apex:pageblock >
         <apex:pageblocksection title="Section1" columns="1">
            <apex:inputField value="{!acc.Phone}" />
            <apex:inputField value="{!acc.Jigsaw}" />
            <apex:inputField value="{!acc.ParentId}" />
            <apex:inputField value="{!acc.Type}" />
         </apex:pageblocksection>
         <apex:pageblocksection title="Section2" columns="1">
            <apex:inputField value="{!acc.BillingCity}" />
            <apex:inputField value="{!acc.Description}" />
         </apex:pageblocksection>
         <apex:pageBlockButtons>
            <apex:commandButton value="submit" action="{!submit}"/>
         </apex:pageBlockButtons>
      </apex:pageblock>
   </apex:form>
</apex:page>


This may help you. if still the page is not redirecting there must be an issue with your access setting so there will be an exception happen and that should be caught in catch block. verify the debug log if redirect is not working.

let me know, if it helps you or need any help :)

shiva.sfdc.backup@gmail.com