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
User 444User 444 

How to assign a bulk of apex class ids in below query?

insert new SetupEntityAccess( ParentId = '0PS...', // PermissionSet ID SetupEntityId = '01p...' // ApexClass ID );

In above apex class, i want to add some 1000 apex class ids in setupentityid, how is it possible? Thanks!
Best Answer chosen by User 444
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You can try as below.
 
List<ApexClass> cs= new lIST<Apexclass>();
cs=[select id,name from ApexClass ];
List<Id> apexids=new List<Id>();
List<SetupEntityAccess> sealist= new List<SetupEntityAccess>();
For(ApexClass acs:cs){
    SetupEntityAccess scs= new SetupEntityAccess();
    scs.ParentId ='0PS5';//permissionsetid
    scs.SetupEntityId =acs.id;
   sealist.ADD(scs);
}
insert sealist;

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You can try as below.
 
List<ApexClass> cs= new lIST<Apexclass>();
cs=[select id,name from ApexClass ];
List<Id> apexids=new List<Id>();
List<SetupEntityAccess> sealist= new List<SetupEntityAccess>();
For(ApexClass acs:cs){
    SetupEntityAccess scs= new SetupEntityAccess();
    scs.ParentId ='0PS5';//permissionsetid
    scs.SetupEntityId =acs.id;
   sealist.ADD(scs);
}
insert sealist;

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Mukesh pal 7Mukesh pal 7

check this example 

List<Id> classIds = new List<Id>{'classId1', 'classId2', 'classId3'};
List<MyObject__c> records = [SELECT Id, Name FROM MyObject__c WHERE Apex_Class__c IN :classIds];

In this example, the Apex_Class__c field on the MyObject__c object is being matched against the list of class ids in the classIds variable. You can replace the classIds variable with any other list of Id values to match different sets of records. the SOQL IN operator has a limit of 20,000 items per list, so if you have a large number of Apex class ids to match against, you may need to split them into multiple queries or use other techniques such as filtering by related objects.