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
birdofpreybirdofprey 

SOQL SELECT Where IN Clause in PHP

I try doing a Where IN CLause from php where my $campaignID is a 1-dem array, any ideas if thise works?

 

SELECT Id FROM Campaign WHERE Id IN ('$campaignID')

 

Best Answer chosen by Admin (Salesforce Developers) 
DoogleDoogle

Hi,

 

Hopefully this helps.  I used COUNT, IN and GROUP BY successfully using the below query string.

 

$query = "SELECT fieldone__c, COUNT(Id) from table__c WHERE fieldtwo__c IN (" . $this->sClass->csv . ") GROUP BY fieldone__c";

 

Note: $this->myClass->csv = 'M0010', 'M0009'

 

This means the PHP inturperter will create the following string.

 

SELECT fieldone__c, COUNT(Id) from table__c WHERE fieldtwo__c IN ('M0010', 'M0009') GROUP BY fieldone__c

 

Lastly, make sure you have the correct field name before the IN clause. 

 

Regards,

Doug C.

All Answers

TheIntegratorTheIntegrator

As far as I know, $campaignID should be a comma separated string of strings in this case

 

in your case, when PHP makes the call, salesforce should see something like this:

 

SELECT Id FROM Campaign WHERE Id IN ('00190000003Ncuo', '00190000003Ncuj')

DoogleDoogle

Hi,

 

Hopefully this helps.  I used COUNT, IN and GROUP BY successfully using the below query string.

 

$query = "SELECT fieldone__c, COUNT(Id) from table__c WHERE fieldtwo__c IN (" . $this->sClass->csv . ") GROUP BY fieldone__c";

 

Note: $this->myClass->csv = 'M0010', 'M0009'

 

This means the PHP inturperter will create the following string.

 

SELECT fieldone__c, COUNT(Id) from table__c WHERE fieldtwo__c IN ('M0010', 'M0009') GROUP BY fieldone__c

 

Lastly, make sure you have the correct field name before the IN clause. 

 

Regards,

Doug C.

This was selected as the best answer