+ Start a Discussion
sandeepathadusandeepathadu 

urgent plz help me with the senario

hi all
 
i have written a trigger that will update the account owner name on saving a ticket instead of admin name which is by default
 
for ex: if i save a ticket i get admin name generally but i have written a trigger and instead of admin name it updates account owner name now the issue is when i deactivate the account owner it should update the user name for this i have written this trigger
trigger caseAssignWebCaseToAccountOwner on Case (before update) {
for(case c :trigger.new){
user u = [Select id,name,IsActive from user limit 1 ];
if(c.Origin == 'Portal' && c.SSP_owner_Update__c==false && c.accountid!=null && u.isactive == True){
 account a = [select id,name,OwnerId from account where id=:c.accountid];
 c.ownerid=a.ownerID;
 c.SSP_owner_Update__c=true;
}
  if(c.Origin == 'Portal' && u.isactive == False)
  
 c.ownerid= '005Q0000000f95r';

}
}
but now when i deactivate the account owner and save the ticket it is saying

 
Operation with Inactive UserAn operation was performed with an inactive user. plz help how to update the ticket name with the user login when we deactivate a account

 

TejTej

First thing please do not hard code Id's.

 

In your query

 

ID profile = [select id from Profile where name = 'System Administrator'].id; 

 

User u = [Select id,name,IsActive from user where ProfileId = profile limit 1 ];

 

Now you have a Active Admin User.

 

Now when you are updating the account owner update it with U.Id. 

 

Hope this helps. 

Thnks

sandeepathadusandeepathadu

hi thanks for the reply but its giving me admin name but i wnt the name of adminstrator i mean the one who created the login

sandeepathadusandeepathadu

thank u tej it works