使用下面代码的方式添加:
String apexClassName = 'ckwm_WeComAuthLoginAuraAction';
ApexClass apexClass = [SELECT Id, Name FROM ApexClass WHERE Name = :apexClassName LIMIT 1];
String profileId = '00ebW000000JZBl'; // Profile ID
// Get the permission set related to the profile
PermissionSet permissionSet = [SELECT Id, Name FROM PermissionSet WHERE ProfileId = :profileId LIMIT 1];
if (apexClass != null && permissionSet != null){
// Grant access to the Apex class
SetupEntityAccess setupEntityAccess = new SetupEntityAccess();
setupEntityAccess.ParentId = permissionSet.Id;
setupEntityAccess.SetupEntityId = apexClass.Id;
insert setupEntityAccess;
System.debug('Apex class ' + apexClassName + ' assigned to profile with ID: ' + profileId);
} else {
System.debug('Apex class or profile not found.');
}