You need to sign in to do that
Don't have an account?
VF question
how to add New Button in VF search page.
like if our data is not found then a NEW Button there with the help of this button we can create new record
my Search page works only m looking for NEW Button
<apex:page StandardController="Work_Order__c" extensions="Search">
<apex:form >
<apex:outputLabel >Enter The Work Order Number ::- </apex:outputLabel>
<apex:inputText value="{!searchText}"/><br/>
<apex:commandButton value="Search" Action="{!Search}"/><br/>
<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 Search(ApexPages.StandardController controller)
{
}
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';
}
else
{
msg='Work Order Number already Exist' ;
}
}
}
like if our data is not found then a NEW Button there with the help of this button we can create new record
my Search page works only m looking for NEW Button
<apex:page StandardController="Work_Order__c" extensions="Search">
<apex:form >
<apex:outputLabel >Enter The Work Order Number ::- </apex:outputLabel>
<apex:inputText value="{!searchText}"/><br/>
<apex:commandButton value="Search" Action="{!Search}"/><br/>
<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 Search(ApexPages.StandardController controller)
{
}
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';
}
else
{
msg='Work Order Number already Exist' ;
}
}
}
And then in your controller you can have a method that redirects a user off to the create method...
Of course, the button will always there, so you might want to use the "Rendered" attribute to determine if it shows. You could put a flag on the controller and set it when the search is performed:
and then in the controller have
and after your message about there being no search results, set showNew to true.
thanks for your halp .but m geting error plz let me know where m doing worng .....
<apex:page StandardController="Work_Order__c" extensions="Search">
<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 = false;
public Search(ApexPages.StandardController controller)
{
}
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';
}
else
{
msg='Work Order Number already Exist' ;
}
}
public PageReference createRecord() {
PageReference createPage = new ApexPages.StandardController(Work_Order__c);
createPage.setRedirect(true);
return createPage;
}
}
see - I was missing a get and set on the boolean definition (unless you wrote getCreateNew() instead) and then I've added the setting of it to true in your code (and also a set to false, to hide the button should they reperform the search)
any better?
now m geting this error Error: Search Compile Error: Variable does not exist: Work_Order__c at line 67 column 67
in this line
PageReference createPage=new ApexPages.StandardController(Work_Order__c);
i have Work_Order__c but its giving error .i have no idea why..
thanks
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_ctor.htm