2011-11-09 58 views

回答

0

是的。雖然DML is forbidden Profile對象本身,您可以更改用戶的個人資料(從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),用於根尖類,你可以不寫以上代碼

相關問題