You need to sign in to do that
Don't have an account?
adding a standard save to a custom object
Hi folks..i am new to salesforce/visualforce/apex. I have created a custom object Deal__c and have created a button to search the deals based on the users input. I need to add the save button. Can someone plz show how to add?i tried creating a stnadard controller and using an extension. But it was showing constructor errror.Any help is greatly appreciated.
public with sharing class Demo2 {
public List<Deal__c> SearchResult{get;set;}
public String SelectedValue1{get;set;}
public String SelectedValue2{get;set;}
public Deal__c SearchCriteria{get;set;}
public Demo2 ()
{
SearchCriteria = new Deal__c();
}
public void filterRecord()
{
SearchCriteria = new Deal__c();
SearchResult = new List<Deal__c>();
SearchResult = [SELECT Deal_Name__c,
Deal_Type__c
FROM Deal__c
WHERE Deal_Name__c =: SearchCriteria.Deal_Name__c
AND Deal_Type__c =: SearchCriteria.Deal_Type__c];
if(SearchResult.size() == 0)
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display'));
}
}
}
<apex:page controller="Demo2">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!SearchCriteria.Deal_Name__c}"/>
<apex:inputField value="{!SearchCriteria.Deal_Type__c}"/>
<apex:commandButton value="Search" action="{!filterRecord}" reRender="applicantTbl,error"/>
</apex:pageBlockSection>
<apex:pageBlockTable styleClass="appTbl" id="applicantTbl" value="{!SearchResult}" var="rec">
<apex:column value="{!rec.Deal_Name__c}"/>
<apex:column value="{!rec.Deal_Type__c}"/>
<apex:outputLink value="{!URLFOR($Page.customDetailPage, '', [id=Deal__c.id])" />
</apex:pageBlockTable>
<apex:pageMessages id="error"></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi,
Just add the below code to your class to leverage standard controller, after adding this you can use standard save in your class.
public Demo2(ApexPages.StandardController controller) { }
Thanks,
Kunal
I tried adding the code you provided. It still doesnt work. My controller extension looks like this. Anyways thanks for your reply.
public with sharing class Demo2 {
public List<Deal__c> SearchResult{get;set;}
public String SelectedValue1{get;set;}
public String SelectedValue2{get;set;}
public Deal__c SearchCriteria{get;set;}
public Demo2 ()
{
SearchCriteria = new Deal__c();
}
public Demo2(ApexPages.StandardController controller) {
}
public void filterRecord()
{
SearchCriteria = new Deal__c();
SearchResult = new List<Deal__c>();
SearchResult = [SELECT Deal_Name__c,
Deal_Type__c
FROM Deal__c
WHERE Deal_Name__c =: SearchCriteria.Deal_Name__c
AND Deal_Type__c =: SearchCriteria.Deal_Type__c];
if(SearchResult.size() == 0)
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display'));
}
}
}
Have you added the standard controller to your page??
<apex:page standardController="Deal__c" extensions="Demo2">
??
<apex:page standardcontroller="Deal__c" extensions="Demo2">
<apex:page standardcontroller="Deal__c" extensions="Demo2">
In the controller ,add constructor like this
public Demo2(ApexPages.StandardController controller) {
SearchCriteria = (Deal__c)new Deal__c();
}
controller.save()---> will call standard sava function.
I tried it with no sucess. Can you please edit on my pgm and post the program. I feel that i am missing something.
Can you please explain a bit what is the functionality you are trying to implement? After searching a record what will you edit?