1

I am a newbie to salesforce coming from java world. I was working on a piece of functionality where user select search criteria, i build a dynamic soql based on that and display records on the same page, and each record is associated with an edit link.

The problem with the "EDIT Link" is that it only works without rerender attribute on the command button.

I don't want a complete complete page refresh, so i am using the rerender attribute on the command button to partially update the page block table.

But this is breaking the "EDIT" links and they become unresponsive. I have inspected the element itself and i can see that the href link seems to be just fine.

Can anyone help me understand what could be causing this peculiar behavior?

Below is the complete code for custom VF page and custom controller

CUSTOM VF PAGE

<apex:page controller="AccountList" tabStyle="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="searchText">Search By Name</apex:outputLabel>
                    <apex:inputText id="searchByName" value="{!searchByName}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="searchText">Search By Rating</apex:outputLabel>
                    <apex:selectRadio value="{!searchByRating}">
                        <apex:selectOption itemLabel="Cold" itemValue="Cold"></apex:selectOption>
                        <apex:selectOption itemLabel="Hot" itemValue="Hot"></apex:selectOption>
                        <apex:selectOption itemLabel="Warm" itemValue="Warm"></apex:selectOption>
                        </apex:selectRadio>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <!-- Implement Web Service -->
                    <apex:outputLabel for="searchText">Search By State</apex:outputLabel>
                    <apex:selectList size="1" value="{!searchByState}">
                        <apex:selectOption itemLabel="" itemValue=""></apex:selectOption>
                        <apex:selectOption itemLabel="KS" itemValue="KS"></apex:selectOption>
                        <apex:selectOption itemLabel="CA" itemValue="CA"></apex:selectOption>
                        </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <!-- Implement Web Service -->
                    <apex:outputLabel for="searchText">Logical Operator</apex:outputLabel>
                    <apex:selectList size="1" value="{!searchCriteria}">
                        <apex:selectOption itemLabel="AND" itemValue="AND"></apex:selectOption>
                        <apex:selectOption itemLabel="OR" itemValue="OR"></apex:selectOption>
                        </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="searchText">Search </apex:outputLabel>
                    <apex:commandButton value="Go1!" action="{!doSearch}" reRender="theBlock"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection title="Results" columns="1">
                <apex:actionRegion >
                    <apex:pageBlockTable value="{!accounts}" var="account" id="theBlock">
                        <apex:column headerValue="Action">
                        <apex:outputLink value="{!URLFOR($Action.Account.Edit, account.Id)}">Edit (Action)</apex:outputLink> - 
                        <apex:outputLink value="/{!account.Id}/e?">Edit (URL)</apex:outputLink>
                        </apex:column>
                        <apex:column value="{!account.Name}" />
                        <apex:column value="{!account.Rating}" />
                        <apex:column value="{!account.BillingState}" />            
                    </apex:pageBlockTable>
                </apex:actionRegion>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

CUSTOM CONTROLLER

public class AccountList {

String searchTerms = '';

public String showGo { get; set; }

public String searchCriteria { get; set; }

public String searchByState { get; set; }

public String searchByRating { get; set; }

public String searchByName { get; set; }

public List<Account> accounts {
    get;
    private set;
}

public PageReference doSearch() {

    searchTerms = 'select Name, Rating, BillingState from Account where';
    if (!String.isEmpty(searchByName))
        searchTerms += ' Name LIKE \''+String.escapeSingleQuotes(searchByName)+'%\'';
    if (!String.isEmpty(searchByRating)){
        if (!String.isEmpty(searchByName)){
            searchTerms += ' '+searchCriteria+' Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
            //searchTerms += ' or Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
        } else {
            searchTerms += ' Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
        }                
    }                
    if (!String.isEmpty(searchByState)){
        if (!String.isEmpty(searchByName) || !String.isEmpty(searchByRating)){
            searchTerms += ' '+searchCriteria+' BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
            //searchTerms += ' or BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
        } else {
            searchTerms += ' BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
        }
    } 
    if(!String.isEmpty(searchTerms)){
        //results = (List<Account>)[FIND :searchTerms RETURNING Account(Name, Rating, BillingState)][0];
        System.debug('searchTerms -'+searchTerms);
        accounts = Database.query(searchTerms);
    }

    return null;
}

/*public AccountList() {
    accounts = [select name, rating, billingstate from account];
}*/

}
7
  • I tested your page in my instance and its working ..Not sure which browser you are testing .It looks functional to me Commented Nov 19, 2015 at 3:44
  • HiMohith, I have just tested it again on the latest versions of chrome and firefox and it won't work. Have you specifically tested the "EDIT" links for each record?
    – SFDC K5
    Commented Nov 19, 2015 at 3:51
  • Yes..They are working..both your edit links Commented Nov 19, 2015 at 3:51
  • Which browser are you using?
    – SFDC K5
    Commented Nov 19, 2015 at 4:03
  • Chrome ..very surprising its not working for you Commented Nov 19, 2015 at 4:04

1 Answer 1

0

You are not fetching the id field of account in your SOQL query but you are referring to that field in your commandLink.

Could you please try once with the ID field in your SOQL?

6
  • Does it not break and say field used without querying..weird that it works in my org Commented Nov 19, 2015 at 8:43
  • Gosh! I just tried without the ID field and it worked for me as well. I am using firefox. Commented Nov 19, 2015 at 9:21
  • @SFDC K5, here comes the typical question. What do you mean by 'break' the link doesn't appear or clicking the link doesnt take you to next page? Whats the URL shows when you HOVER your link??? Commented Nov 19, 2015 at 9:29
  • @SantanuHalder, I meant click the link doesn't take you to next page. This is the generated link. <a href="na34.salesforce.com/0016100000Acb7EAAR/… (Action)</a>
    – SFDC K5
    Commented Nov 19, 2015 at 17:58
  • @SantanuHalder, I have also added the ID field now. Still it's the same problem.
    – SFDC K5
    Commented Nov 19, 2015 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .