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
rajubalajirajubalaji 

how to write a soql query for the parameter variable

Hi all,

please find the below code for reference my case was i dont want to get the user from user table.i need to get the users from the parameter variable called as alluser.anyone please tell me the soql query for how to write a query for parameter variable class.

Public Static List<String> GetUserListForTaskAssignmentNew(List<String> allUser){
        List<String> UserId = new List<String>();
        List<User> assignUserList=new List<User>();
        String User = null;
        List<AggregateResult> TaskCount = [SELECT ownerId, count(Type) from Task where createdDate<=Today and GroupId In (select id from alluser where id=:ownerId) group By ownerID];
        {
            if(allUser.size() > 0)
            {
                 
            }
        }
        return UserId;
    }
}

Thank You in advance.
Best Answer chosen by rajubalaji
Rounak SharmaRounak Sharma
hello balaji,
Now i got to know what is your requirement.
please look at my sample code below
public class EventsDelete {
@InvocableMethod
public static void deleteEvents(List<Id> opportunityIds) {
List<Event> events = [SELECT id from Event where whatId IN:opportunityIds ];
delete events;
}
}
here I am doing almost similar thing

All Answers

Rounak SharmaRounak Sharma

hi balaji,

i assume that you want your soql in this way
String myTestString = 'TestName';
List<sObject> sobjList = Database.query('SELECT Id FROM MyCustomObject__c WHERE Name = :myTestString');

rajubalajirajubalaji
Hi rounak sharam, Thank you so much for reply.but By using that query I was getting error.i need to write query on parameter variable class not on table.
Rounak SharmaRounak Sharma
hello balaji,
Now i got to know what is your requirement.
please look at my sample code below
public class EventsDelete {
@InvocableMethod
public static void deleteEvents(List<Id> opportunityIds) {
List<Event> events = [SELECT id from Event where whatId IN:opportunityIds ];
delete events;
}
}
here I am doing almost similar thing
This was selected as the best answer
rajubalajirajubalaji
Hi Rounak,

By Using one query.

select ownerId, Count(type) from task where CreatedDate<=Today and ownerId In(Select Id from user where allUser='+OwnerId+') group By ownerId

But i am getting below please chck and reply me for futher process.


[object Object]: ownerId In(Select Id from user where allUser='+OwnerId+') group By ownerId ^ ERROR at Row:1:Column:105 No such column 'allUser' on entity 'User'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Rounak SharmaRounak Sharma
hello,
alluser is a parameter which is a input type and it's data is coming. so you can not use like that as it is not a field in user object. rather you can have ownerId IN: allUser.
rajubalajirajubalaji
Hi rounak,

By your guideline i have follow the same thing but i am getting below error.

Unknown error parsing query

select ownerId, Count(type) from task where CreatedDate<=Today and OwnerId In(Select Id from user where OwnerId In:'+allUser+') Group By owner Id
Rounak SharmaRounak Sharma

hi balaji,
you dont have to use + sign and niether the ' ' . you simply have to write
select ownerId, Count(type) from task where CreatedDate<=Today and OwnerId In(Select Id from user where OwnerId IN:allUser) Group By owner Id. This query will not work in query editor as allUser cant be determined in that.

thanks