You need to sign in to do that
Don't have an account?
search page by vf
creating a search page if entered record is found then give as mess record it exist if not then gives a New button to create New record ..
this code is works for search but when m trying to add new button its gives error......
<apex:page StandardController="Work_Order__c" extensions="Search" showheader="true" action="{!redirect}">
<apex:form >
<apex:outputLabel >Enter The Work Order Number ::- </apex:outputLabel>
<apex:inputText value="{!searchText}"/><br/>
<apex:commandButton value="Search" Action="{!Search}"/><br/>
<apex:commandButton value="New" Action="{!createNew}" rendered="{!showNew}"/>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputText >Message: {!msg}</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller............
public class Search
{
public String SearchText{get;set;}
public Work_Order__c wo{get;set;}
public string msg{get;set;}
public boolean showNew { get; set;}
public Search(ApexPages.StandardController controller)
{
showNew = false;
}
public void search()
{
List<Work_Order__c> wolist=[select id,name from Work_Order__c];
for(Work_Order__c w:wolist)
{
if(w.name.containsIgnorecase(searchText))
wo=w;
}
if(wo==null)
{
msg='Work Order Number Not Exist u can create New by given link below';
showNew = true;
}
else
{
msg='Work Order Number already Exist' ;
showNew = true;
}
}
public PageReference createRecord() {
PageReference createPage=new ApexPages.StandardController(Work_Order__c);
createPage.setRedirect(true);
return createPage;
}
}
this code is works for search but when m trying to add new button its gives error......
<apex:page StandardController="Work_Order__c" extensions="Search" showheader="true" action="{!redirect}">
<apex:form >
<apex:outputLabel >Enter The Work Order Number ::- </apex:outputLabel>
<apex:inputText value="{!searchText}"/><br/>
<apex:commandButton value="Search" Action="{!Search}"/><br/>
<apex:commandButton value="New" Action="{!createNew}" rendered="{!showNew}"/>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputText >Message: {!msg}</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller............
public class Search
{
public String SearchText{get;set;}
public Work_Order__c wo{get;set;}
public string msg{get;set;}
public boolean showNew { get; set;}
public Search(ApexPages.StandardController controller)
{
showNew = false;
}
public void search()
{
List<Work_Order__c> wolist=[select id,name from Work_Order__c];
for(Work_Order__c w:wolist)
{
if(w.name.containsIgnorecase(searchText))
wo=w;
}
if(wo==null)
{
msg='Work Order Number Not Exist u can create New by given link below';
showNew = true;
}
else
{
msg='Work Order Number already Exist' ;
showNew = true;
}
}
public PageReference createRecord() {
PageReference createPage=new ApexPages.StandardController(Work_Order__c);
createPage.setRedirect(true);
return createPage;
}
}
You need to edit the save record method you have written as it doesn't seem to be implemented correctly in the above code.
Please check the code mentioned on this blog to get an idea as to how to insert a new record in DB : http://blog.jeffdouglas.com/2010/04/27/create-a-new-record-in-force-com-sites/