{
public List<Contact> contacts { get; set; }
public String name { get; set; }
public searchClass()
{
contacts = new List<Contact>();
}
public pageReference searchcontacts()
{
contacts = [select Id
,Name
from Contact
where Name = :name];
if(contacts.size() == 0) {
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
ApexPages.addMessage(myMsg);
//ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'No Records Found'));
}
if(contacts.size() == 1)
{
for(Contact con :contacts ){
// In this This section my problem not redirecting
PageReference pageRef = new PageReference('con.Id');
return pageRef;
}
}
return null;
}
}
page
<apex:page controller="searchClass">
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockSection id="contact-table" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name"/>
<apex:inputText value="{!name}" />
</apex:pageBlockSectionItem>
<apex:commandButton value="Search" action="{!searchcontacts}" reRender="contact-table" >
</apex:commandButton>
<apex:pageBlockTable value="{!contacts}" var="c" >
<apex:column >
<apex:outputlink value="/{!c.Id}"> {!c.Name}</apex:outputlink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
1 réponse
HI Srikanth,I tried your code in my org and see the error message as "Formula Expression is required on the action attributes."You might want to try the approach mentioned in https://developer.salesforce.com/forums/?id=906F000000099FyIAINote: page reference cannot just return a string, or you get the error mentioned above.If this information helps, please mark the answer as best.Thank you