function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jasonkorjasonkor 

I have a trigger but need help with a class

I wrote this trigger, with help from the community, to update owner to current user upon status closed.  I am in need of a class and don't throughly understand the language yet (taking classes).  Does any one know where to start?

 

trigger CaseUpdate on Case (before update) {
List<User> usersRoleName =[select Id, Name, UserRole.Name  from User Where Id=:UserInfo.getUserId() AND UserRole.Name ='Technical Services'];
    if (Trigger.new.size() == 1) {  
        // if a Case has been updated to Closed
        if (Trigger.new[0].Status == 'Closed' && !usersRoleName.isEmpty()) {  
            // Change Trigger.old[0].OwnerId to Current User ID
            Trigger.new[0].OwnerId = UserInfo.getUserId();
        }
    }
}

s_k_as_k_a

Can you post your Requirement Clearly.

jasonkorjasonkor

I am trying to create a class that matches my current trigger.  My current trigger should assign the case to the current user upon case close but I am limiting it to certain roles

s_k_as_k_a

Try this code

 

trigger CaseUpdate on Case (before update) {
List<case> CasesList = [select id, status, ownerId from Case where id in: trigger.new];
Id TechroleId = [select id from role where name ='Technical Services'];
for(case  c :  CasesList)
	{
	   if(c.status == 'closed' && userInfo.getRoleId == TechroleId)
		{
		   c.ownerId = userInfo.getuserId;
		}
	}
}

 

sivaextsivaext

hi 

 

i think no need any class in this situation. Trigger is best option.