2011-11-09 29 views

答えて

0

はい。プロファイルオブジェクト自体にDML is forbiddenが、あなたは(Apexの開発者ガイドから)ユーザーのプロファイルを変更することができます。

Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
User u = new User(Alias = 'standt', Email='[email protected]', 
    EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
    LocaleSidKey='en_US', ProfileId = p.Id, // <--- 
    TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]'); 

System.runAs(u) 
{ 
    // The following code runs as user 'u' 
    System.debug('Current User: ' + UserInfo.getUserName()); 
    System.debug('Current Profile: ' + UserInfo.getProfileId()); 
} 
0

System.runAs(U)のみテストクラスで使用される、Apexクラスのためにあなたが書き込むことはできません上記コード

関連する問題