0

I am new to SF apex programming,

Can any one help me out of this error and suggest me on the code written.

Thanks for your help,

public class c6{

string keyword;
List<Account> acts;

public string getkeyword(){
return keyword;
}

public List<Account> getacts(){
return acts;
}

public void setkeyword(String s){
keyword = s;
}

public PageReference search(){
acts = (List<Account>)[FIND: keyword Returning Account(Name, Type, Industry, Phone, Fax)]
return null;
}

}

0
1

You're missing a semi-colon (;) after the previous line. Even inline queries need to end with a semi-colon:

acts = (List<Account>)[FIND: keyword Returning Account(Name, Type, Industry, Phone, Fax)];
return null;
4
  • public class c6{ string keyword; List<Account> acts; public string getkeyword(){ return keyword; } public List<Account> getacts(){ return acts; } public void setkeyword(String S){ keyword = S; } public PageReference search(){ acts = (List<Account>)[FIND: keyword Returning Account(Name, Type, Industry, Phone, Fax)]; return null; } } – Jay Nov 8 '15 at 15:41
  • Hi Smith - Still I am getting the following error, – Jay Nov 8 '15 at 15:42
  • Error: Compile Error: Incompatible types since an instance of List<List<SObject>> is never an instance of List<Account> at line 19 column 8 – Jay Nov 8 '15 at 15:42
  • @Jay You'll need to get the first list of lists, like this: [FIND ... ][0]. Even if there's only one returned object list, it's still a list of lists. – sfdcfox Nov 9 '15 at 5:42
0

VF Page

Visualforce Source Page coding:

< apex:page controller="cl3">


    <apex:form >


        <apex:pageBlock title="List of accounts">

            <apex:pageBlockSection >

                <apex:inputField value="{!Fields.Industry}"/>

            <apex:pageBlockSectionItem>

                <a>Search </a>      <apex:inputText value="{!Keyword}" title="Search" size="25"/>

            </apex:pageBlockSectionItem>

            </apex:pageBlockSection> 

            <apex:pageBlockButtons >

                <apex:commandButton value="Show All" Action="{!Showall}"     reRender="mylayout"/>

                <apex:commandButton value="Filter"   Action="{!ShowFilter}"  reRender="mylayout"/>                                                         

                <apex:commandButton value="Search"   Action="{!SearchText}"  reRender="mylayout"/>                

            </apex:pageBlockButtons>

            <apex:pageBlockTable value="{!Displayrecords}" var="Record" id="mylayout">
                <apex:column value="{!Record.Name}"/>
                <apex:column value="{!Record.Type}"/>
                <apex:column value="{!Record.Industry}"/>

            </apex:pageBlockTable>

        </apex:pageBlock>

    </apex:form>

</apex:page>

VF CLASS

public class cl3 {
    Account   acc1 = new Account();
    String    keywordText;

    List<Account> acc;
    List<List<Account>>  acc2;

    public Account getFields()
    {
          return acc1;
    }
    public void setKeyword(String s)
    {
        keywordText = s;
    }
    public String getKeyword()
    {

        return keywordText;
    }
    public PageReference SearchText()
    {
        List<List<sObject>> results;       
        results = [FIND :keywordText IN ALL FIELDS RETURNING Account (Name, Type, Industry)];
        sObject[] res = ((List<sObject>)results[0]);
        acc = res;  
        return null;
    }

    public PageReference Showall()
    {
        acc = [ select Name,Type,Industry from Account];

        return null;
    }

    public PageReference ShowFilter()

    {
        String v_val;

        if(acc1.Industry <> '') {

          v_val = acc1.Industry;    

          acc = [ select Name,Type,Industry from Account where Industry = :v_val ];

        }else
        {
            Showall();
        }


        return null;
    }

    public Account[] getDisplayrecords()
    {
        return acc;
    } 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.