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
ag_nameag_name 

REST API SOQL STRING QUERY

Hello, 

 

I'm trying to experiment using the codes for integrating rest api and php by Mr. Pat Patterson,  I wanted to insert the variable $id parameter to the following soql string query but it isn't working. Please help.

 

function show_accounts($instance_url, $access_token,$id) {
    $query = "SELECT Name, Id from Account WHERE Id =: \'' $id '\'";
    $url = "$instance_url/services/data/v20.0/query?q=" .    urlencode($query);
.
.
.
.

}

 

The $id parameter should be salesforce id that will return by the query. Am I missing something? Please advise.

 

Salesforce WizardSalesforce Wizard

Ag_Name --

 

this is a guess, but I think what you need to do is remove the =: part of your query string. When you're building the string it's going to put the value of the variable in the string -- not the variable itself.

 

Example I'm passing "AccountName" into my query string. so I format it:

"/query?q=SELECT+id+,+name+,+CPM_Acute_Beds__c+,+BillingCity+,+BillingState+FROM+Account+where+IsPersonAccount=false+and+RecordTypeId='012400000009ZXK'+and+Name+like'"+AccountName+"'+limit+10";

 And it outputs:

/query?q=SELECT+id+,+name+,+CPM_Acute_Beds__c+,+BillingCity+,+BillingState+FROM+Account+where+IsPersonAccount=false+and+RecordTypeId='012400000009ZXK'+and+Name+like'%25poudre%25'+limit+10

 Note - my AccountName variable contains the %25 before and after the name.