You need to sign in to do that
Don't have an account?
Manish Anand 12
Error- Unexpected Token: 'List'
Hi,
I am trying to execute below SOSL query in Apexcode:
List<List<Sobject>> searchlist=[FIND 'Pencil*' IN ALL FIELDS RETURNING Merchandise__c (Id,Name), Invoice_Statement__c];
Merchandise__c[] merList = ((List<Merchandise__c>) searchList[0]);
Invoice_Statement__c[] invList = ((List<Invoice_Statement__c) searchList[1]);
System.debug('Found' + merList.size() + 'merchandise items.');
System.debug('Found' + invList.size() + 'invoice statements.');
I get an error message- Unexpected Token: 'List'
What could be the reason?
I am trying to execute below SOSL query in Apexcode:
List<List<Sobject>> searchlist=[FIND 'Pencil*' IN ALL FIELDS RETURNING Merchandise__c (Id,Name), Invoice_Statement__c];
Merchandise__c[] merList = ((List<Merchandise__c>) searchList[0]);
Invoice_Statement__c[] invList = ((List<Invoice_Statement__c) searchList[1]);
System.debug('Found' + merList.size() + 'merchandise items.');
System.debug('Found' + invList.size() + 'invoice statements.');
I get an error message- Unexpected Token: 'List'
What could be the reason?
You're missing a closing '>'
You can remove the type casting of Lists.
See the below code:
public class SOSLExample {
public void findRecords() {
//List<List<SObject>> listObj = [FIND 'Test' IN ALL FIELDS returning Account, Contact, Case, Lead];
List<List<SObject>> listObj = [FIND 'Test' IN ALL FIELDS returning Account(Id, Name, AccountNumber), Contact, Case, Lead];
System.debug('===================listObj:'+listObj);
for(List<SObject> lObj: listObj) {
System.debug('---------------lObj:'+lObj);
}
List<Account> accList = listObj.get(0);
List<Contact> conList = listObj.get(1);
List<Case> caseList = listObj.get(2);
List<Lead> leList = listObj.get(3);
System.debug('********************AccList:'+accList);
for(Account acc: accList) {
System.debug('------------------Account acc:'+acc);
System.debug('------------------acc.Id:'+acc.Id);
System.debug('------------------acc.Name:'+acc.Name);
}
}
}
Which I have written in my developer sandbox and it works well.
Regards,
Mahesh
@Mahesh:- I copy-pasted your code in my developer sandbox, looks fine to me, but when I execute it it gives following error.
No such column 'AccountNumber' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
I am new to salesforce.Not sure, what I am missing here.
Try this and check the results.
Regards,
Mahesh
Regards,
Manish
How are you executing the method.
Go to Developer Console --> Debug --> Open Execute Anonymous Window
SOSLExample se = new SOSLExample();
se.findRecords();
select the checkbox 'Open Log' and click on the Execute button.
Regards,
Mahesh
I see it working.Thanks.
But do you know the reason, why it gave an error with 'AccountNumber'? It looks fine to me.
Regards,
Manish
--> the field is set to Hidden via field level security for the current user profile (if you're an admin fields can still be hidden) you will receive the above error.
--> If the organization is using Person Accounts and you are accessing a PersonAccount record then this field may not be available for the person account record type.
Regards,
Mahesh
It worked !!. Thanks for your responses.Appreciate it.
Regards,
Manish.
Please mark it as solved.
Regards,
Mahesh
Could you please mark it as solved.
Regards,
Mahesh
I am totally new to this platform.How do I mark this as solved?
No problem, I can help you here.
Go to any of the replies and select it as a "Best Answer" and it will automatically marked as "Solved".
Regards,
Mahesh
You can change the status of this Case as well.
Regards,
Mahesh
I don't see an option for "Best Answer" for any of the above replies.
How do I mark this as resolved.
Regards,
Manish.
If you take the mouse pointer to the replies sure you will get an option for selecting the best answer.
Regards,
Mahesh