+ Start a Discussion

how to transfer SQL to SOQL

I have SQL query here, can you help to transfer to SOQL?
Select o.OpportunityId from OpportunityLineItem o inner join PricebookEntry PE on o.PricebookEntryID=PE.ID inner join Product2 P on PE.product2ID=P.Id where P.Id in
(select Product2.Id from Product2 where Product2.Family  not LIKE 'Service%')
This should work: Select (select OpportunityId from OpportunityLineItems), p.Product2Id  from PricebookEntry p where not (p.Product2.Family like 'Service%')

dude not working ,we tried "SELECT Id,AccountId,Name from Contact where not(Name like 'a%')"


Arun thakur 



What is not working, query error or incorrect results?


When I run your query it appears to run just fine. No contacts starting with the letter A is returned.


I need help on following soql


[SELECT Id, Audience__c, Document_Type__c, Title, Last_Update__c, RatingCount, OwnerId FROM ContentVersion WHERE
                   (isEmpty(:domain) = true OR Domain__c = :domain) AND
                   (isEmpty(:compaign) = true OR Campaign__c = :compaign)];


where :domain and :compaign are my member variables of type String. The aim is to appy filter on WHERE clause only if my member variable has value assigned. In case of empty member variable I want pass the check.


This gives me error
Error: Compile Error: unexpected token: ':' at line 54 column 28


I need somethign like in SQL (@Variable IS NULL OR dbField = @Variable)


Please help




One more thing I cannot use LIKE operator since the field I am checking is multipicklist field