function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
r1985r1985 

Query as String

How to give the below query to a string value??

select ID,Name,Opportunity__c,Account__c,Account__r.Owner.isActive,Account__r.name,Account__r.ownerid,Lease_End_Date__c,Install_Date__c,MiF_Category__c from Equipment__c where ((MiF_Category__c='Lease') or (MiF_Category__c='Own')) and ((not Opportunity__r.name like '%_LeasedEquipment%') or (not Opportunity__r.name like '%_OwnedEquipment%')) and Account__r.Owner.isActive=true

 

 

Thanks in advance,

Malar

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Try this :

 

String str = 'select ID,Name,Opportunity__c,Account__c,Account__r.Owner.isActive,Account__r.name,Account__r.ownerid,Lease_End_Date__c,Install_Date__c,MiF_Category__c from Equipment__c where ((MiF_Category__c=\'Lease\') or (MiF_Category__c=\'Own\')) and ((not Opportunity__r.name like \'%_LeasedEquipment%\') or (not Opportunity__r.name like \'%_OwnedEquipment%\')) and Account__r.Owner.isActive=true' ;

 You just need to escape the single quotes.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Ankit AroraAnkit Arora

Try this :

 

String str = 'select ID,Name,Opportunity__c,Account__c,Account__r.Owner.isActive,Account__r.name,Account__r.ownerid,Lease_End_Date__c,Install_Date__c,MiF_Category__c from Equipment__c where ((MiF_Category__c=\'Lease\') or (MiF_Category__c=\'Own\')) and ((not Opportunity__r.name like \'%_LeasedEquipment%\') or (not Opportunity__r.name like \'%_OwnedEquipment%\')) and Account__r.Owner.isActive=true' ;

 You just need to escape the single quotes.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
Shashikant SharmaShashikant Sharma

Use it like this

String SOQLQuery = 'select ID,Name,Opportunity__c,Account__c,Account__r.Owner.isActive,Account__r.name,Account__r.ownerid,Lease_End_Date__c,Install_Date__c,MiF_Category__c from Equipment__c where ((MiF_Category__c=\'Lease\') or (MiF_Category__c=\'Own\')) and ((not Opportunity__r.name like \'%_LeasedEquipment%\') or (not Opportunity__r.name like \'%_OwnedEquipment%\')) and Account__r.Owner.isActive=true';

List<Equipment__c >  listEquipmnet = Database.execute(SOQLQuery);

 

Shashikant SharmaShashikant Sharma

Cross Post

Ankit AroraAnkit Arora

Indeed! And happy to be on same page.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

r1985r1985

Hey thanks guys. Nice to get a timely reply.

 

Thanks,

Malar