+ Start a Discussion
acrozieracrozier 

creating add new button on a custom edit page

Can someone please help me with creating an add new button for a custom object and custom edit page?

BussBuss

Hi,

 

write a VFpage, where create a buuton with command button tag provide value={!Button}

in Controller:

create a method like

public PageReference Button(){

//control button logic here

}

 

Rerds,

Buss(Certified Developer)

acrozieracrozier

right, but I need help with the control button logic.

Chamil MadusankaChamil Madusanka

Hi,

 

public PageReference Button(){

     YourObject obj = new YouObject();

     obj.field1 = 'abc';

     obj.field2 = 'def;

//set your values here as above

insert obj;
return null;
 } 

 

http://salesforceworld.blogspot.com/2011/06/save-attachment-in-apex.html

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog



acrozieracrozier

Thanks Chamil that code worked.  I just can't seem to get my table to rerender after creating a new item.  Below is the code I am using, can anyone tell me what I am doing wrong?

 

<apex:page standardController="AIIncentive__c" extensions="Incent">
    <apex:form >
     <apex:pageBlock >
     <center>
         <strong><apex:outputText > Incentives </apex:outputText></strong><br />
         <apex:outputField Value="{!AIIncentive__c.Job__c}"/>
     </center>
         <apex:pageBlockTable value="{!Incents}" var="incent" id="incentive">
             <apex:column headerValue="QTY">
                 <apex:inputField value="{!incent.QTY__c}"/>
             </apex:column>
             <apex:column headerValue="Description">
                 <apex:inputField value="{!incent.Description__c}"/>
             </apex:column>
             <apex:column headerValue="Honoraria__c">
                 <apex:inputField value="{!incent.Honoraria__c}"/>
             </apex:column>
             <apex:column headerValue="Job #">
                 <apex:outputField Value="{!incent.Job__c}"/>
             </apex:column>
         </apex:PageBlockTable>
    <apex:commandButton value="Save" action="{!save}"/> 
    <apex:commandButton value="New" action="{!Button}" reRender="incentive"/>    
    </apex:pageBlock>
   </apex:form>
 
</apex:page>

 

Chamil MadusankaChamil Madusanka

Hi,

 

Use this scenario. call the method that retrieve data to the table in action method(after insert)

 

public void getTableData(){
   //here is the code for retrieve data to the table

}

public PageReference Button(){

     YourObject obj = new YouObject();

     obj.field1 = 'abc';

     obj.field2 = 'def;

//set your values here as above

insert obj;
getTableData();
return null;
 }

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog