Please find my code below.

trigger PM on Account (after update) {
    for ( Account acc : Trigger.New ) {
        List<Product_Metrics_vod__c> listCon = [Select id,Products_vod__r.Name,Account_vod__c from Product_Metrics_vod__c where Account_vod__c =: acc.id];
        List<Account> accs=database.query('SELECT Id FROM Account WHERE Restricted_Products_vod__c LIKE' + '%' + listCon[0].Products_vod__r.Name + '%');
        if (accs.isEmpty() == false) {
            delete listCon;

Please find the error message here.

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST at line 4 column 93

  • Hi @saikat. Can you add the error message as well? This will contain a line number where the error is happening. – BarCotter Aug 11 '14 at 8:27
  • I am sorry please find the exact error message updated in the question. – Testing_SFDC Aug 11 '14 at 8:30

Listcon is a list of Product_Metrics_vod__c sobjects, but you are using it as a single sobject instance in line 4:

List<ID> Ids=query('SELECT Id FROM Account 
     WHERE Restricted_Products_vod__c LIKE' + '%' + listCon.Products_vod__r.Name + '%');

Also, your query is returning a list of accounts, not IDs, so you'll need to process the returned values to extract the ids if that is what you are looking for.

If you are expecting a single entry in the list, you can access that element using the square bracket notation:

List<Account> accs=query('SELECT Id FROM Account 
         WHERE Restricted_Products_vod__c LIKE' + '%' + listCon[0].Products_vod__r.Name + '%');

I'm also duty bound to point out that you have a SOQL query embedded in a list, so you are likely to breach governor limits in the event that the trigger has to process multiple records. You should look to bulkify your trigger - more information on this is available at:


| improve this answer | |
  • Hi Bob, this soql query will every time return one record only. Will I still face governor limits? – Testing_SFDC Aug 11 '14 at 8:55
  • Hi Bob. I am getting below error when trying to update Account record. My requirement is if Account ID and Product ID in Product metrics exists such that the Account record with that ID is having the same product in Restricted_Products_vod__c in Account object, then delete the Product Metrics record not restrict the update in Account.Please suggest the work around here. Error::Trigger.PM: line 4, column 1 05:04:12.628 (628561359)|FATAL_ERROR|System.QueryException: line 1:60 no viable alternative at character '%' – Testing_SFDC Aug 11 '14 at 9:08
  • I have updated the code as you suggested, it's getting no compilation error. – Testing_SFDC Aug 11 '14 at 9:10
  • 1
    if you are having other issues then creating a new question is the correct thing to do. Altering your original question with the updated code now means that the code in @BobBuzzards answer is invalid. – BarCotter Aug 11 '14 at 9:43
  • Hi Bob, you were right there might be multiple records in Listcon those should be searched in Restricted_Products_vod__c field value of the relevant Account ID. Please suggest the workaround for that. – Testing_SFDC Aug 11 '14 at 10:12

try this one

database.query('SELECT Id FROM Account WHERE Restricted_Products_vod__c LIKE' + '\'%'+listCon[0].Products_vod__r.Name +'%\'');

instead of database.query('SELECT Id FROM Account WHERE Restricted_Products_vod__c LIKE' + '%' + listCon[0].Products_vod__r.Name + '%');

Thanks Nagarjuna

| improve this answer | |
  • Hi Nagarjuna. I am having multiple values in Listcon and I need to search all of them in Restricted_Product_vod__c field of Account ID. If exists all those records should be deleted from Product_Metrics_vod__C. Can you please suggest a workaround for that? – Testing_SFDC Aug 11 '14 at 10:14
  • Also please find the main concern found with Restricted_Products_vod__c field in Account. Link:: salesforce.stackexchange.com/review/suggested-edits/13683 – Testing_SFDC Aug 11 '14 at 10:15

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.