0

I have a Javascript button, I need to check the number of records having same Owner ID through a SOQL aggregate query. ActIds contains the all selected Activity__c records IDs

var ActIds = [];

var AggregateResult_Owner = sforce.connection.query("SELECT OwnerId, count(Id) FROM Activity__c WHERE Id IN  (\'' + ActIds .join('\',\'') + '\')  GROUP BY OwnerId"); 

On click of button, this query is throwing an error 'MALFORMED QUERY'

Any help will be appreciated

1
  • From where is the ActIds array been set with the values Commented Apr 9, 2018 at 9:06

1 Answer 1

2

You can create a String by iterating over the AccIds array in Javascript and then you can add that string into the SOQL query in the where clause

var selectedAccIds=''; 
for(var i=0;i < ActIds.length; i++)
{
    selectedAccIds+="'"+ActIds[i]+"',";
}
selectedAccIds = selectedAccIds.substring(0,selectedAccIds.length - 1);

var queryStr = "SELECT OwnerId, count(Id) FROM Activity__c WHERE Id IN ("+selectedAccIds+") GROUP BY OwnerId"; 

var AggregateResult_Owner = sforce.connection.query(queryStr);

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.