+ Start a Discussion
Staci CaraStaci Cara 

When the Account Owner changes the content of another custom Subject field shall be deleted

Hi guys, 

I am struggling to find a solution to my problem. 

I have the case that if the Account Owner changes to a specific User X a custom field with SObject__c records of this account shall be emptied the else case is already coded.

Can someone please help me with this? 

Thank you in advance!!

 

Best Answer chosen by Staci Cara
PawanKumarPawanKumar
You can look below sample for getting Owner Id as well as Owner Name.
List<Account> accountList = [Select Id,OwnerId,Owner.Name from Account limit 1];
System.debug('OwnerId:'+accountList[0].OwnerId);
System.debug('OwnerId:'+accountList[0].Owner.Name);

All Answers

PawanKumarPawanKumar
You can look below sample for getting Owner Id as well as Owner Name.
List<Account> accountList = [Select Id,OwnerId,Owner.Name from Account limit 1];
System.debug('OwnerId:'+accountList[0].OwnerId);
System.debug('OwnerId:'+accountList[0].Owner.Name);
This was selected as the best answer
PawanKumarPawanKumar
You can use UserInfo.getProfileId() to get current user profiile Id then you can get Name as below.

List<Profile> profileList = [select Name from Profile where id=:UserInfo.getProfileId()];
System.debug('Profile Name:'+profileList[0].Name);