+ Start a Discussion

Urgent !! - Search code not working. Pl. help me.

Hi All,
I am attatching the code I am using to do a search a name column in the Accounts table.  It is returning me " Object reference not set to an instance of an object." and pointing to the line where i am trying to write the length. (Response.Write("Number of Dimensions:" + records.Length );) .
Please help me to correct my search query. I am new to Salesforce and this is the first time trying the search API.
Grateful if someone can respond immediately.
Thanks a lot !!

Here is the code snippet :Code:
sforce.SearchResult  sr = null;
   sr = sfdc.search(" find{fra} in Name fields returning Account(AccountNumber,Name,CreatedDate,Case_Type__c,Amounts_Awarded__c,Case_Status__c)");
   sforce.SearchRecord[] records = sr.searchRecords;
   System.Collections.ArrayList accounts = new System.Collections.ArrayList();
   Response.Write("Number of Dimensions:" + records.Length );
   if (records.Length > 0)
    for (int i = 0; i < records.Length; i++)
     sforce.sObject record = records[i].record;
     if (record.GetType() == typeof(sforce.Account))
    Response.Write("No records were found for the search.");

When there are no results, the records array is null, not an empty array, so records.length will NPE.

Hi ,

Thanks for your response.

There are records in the table, when I export the data using the apex loader into Excel , I see data matching for the name specified in the query.

When I do the search, I am just giving a part of the name instead of the entire name. I am not sure whether this is causing the problem .

Please let me know.