0

MALFORMED_QUERY: Opportunity__r.LeadSource != 'Website'); ^ ERROR at Row:3:Column:89 unexpected token: ;

SELECT Id, OwnerId, WhatId,Reminder_Date_Time__c, WhoId,Record_Type_Name__c, Task_Type__c,
       Assigned_Date__c, Task_Status__c, ActivityDate, Subject, Attended_By__c,Is_Assigned__c 
FROM Task 
WHERE (Task_Status__c != 'Closed') AND ( Opportunity__r.LeadSource != 'Website')
1
  • Please clarify your question. Your title mentions NOT LIKE but you do not have NOT LIKE in your query. Commented Nov 22, 2018 at 6:48

2 Answers 2

2

SOQL queries do not end with a semi-colon. Please remove the semi-colon from the end of your query. The parentheses are also optional.

SELECT Id, OwnerId, WhatId,Reminder_Date_Time__c, WhoId,Record_Type_Name__c, Task_Type__c,
       Assigned_Date__c, Task_Status__c, ActivityDate, Subject, Attended_By__c,
       Is_Assigned__c 
FROM Task 
WHERE Task_Status__c != 'Closed' AND Opportunity__r.LeadSource != 'Website'
2
  • r8 @sfdcfox but it's give me wrong results Commented Nov 22, 2018 at 10:06
  • @user61059 how so? That wasn't in your question. Commented Nov 22, 2018 at 10:09
0

You can try this dynamic soql.

String query = 'SELECT Id, OwnerId, WhatId, Reminder_Date_Time__c, WhoId, Record_Type_Name__c, Task_Type__c, Assigned_Date__c, Task_Status__c, ActivityDate, Subject, Attended_By__c,Is_Assigned__c '+
               +'FROM Task '+
               +'WHERE Task_Status__c != \'Closed\' AND (NOT Opportunity__r.LeadSource LIKE \'%Website%\')';
System.debug(query);

Refer this link for more details http://raydehler.com/cloud/clod/soql-sosl-using-not-like.html

For more on Quoted String Escape Sequences

7
  • it shows unexpected token NOT Commented Nov 22, 2018 at 10:56
  • SELECT Id, OwnerId, WhatId,Reminder_Date_Time__c, WhoId, Record_Type_Name__c, Task_Type__c,Assigned_Date__c, Task_Status__c, ActivityDate, Subject, Attended_By__c,Is_Assigned__c FROM Task WHERE ( Task_Status__c LIKE 'Open') AND( NOT Opportunity__r.LeadSource LIKE 'Website') ***************************************************************************************************** i tried this one but it's not working with my DB records Commented Nov 22, 2018 at 10:56
  • @user61059 Try the updated query Commented Nov 23, 2018 at 5:52
  • with one like and not equal operator it's works by removing parentheses in LIKE condition Commented Nov 23, 2018 at 6:22
  • But if i write SELECT Id, OwnerId, WhatId,Reminder_Date_Time__c, WhoId, Record_Type_Name__c, Task_Type__c,Assigned_Date__c, Task_Status__c, ActivityDate, Subject, Attended_By__c,Is_Assigned__c FROM Task WHERE (NOT Task_Status__c LIKE 'Closed') AND( Opportunity__r.LeadSource != 'Website') .. Still i m getting wrong results Commented Nov 23, 2018 at 6:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.