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
ch ranjeethch ranjeeth 

when ever the record is created with system administrator profile it should update the Non System Admin Case field with yes otherwise No. I tried below code but its not working...

trigger contactcategory on Contact (before insert,before update)
{
  set<id> set1=new set<id>();
  map<id,string> map1=new map<id,id>();
   for(Contact c:trigger.new)
   {
    set1.add(c.ownerid);
   }
  
   list<user> userlist=[select id,profile.name from user where id in:set1];
   for(user u:userlist)
   {
   map1.put(u.id,u.profile.name);
   }
   for(contact c:trigger.new)
   {
        string s=map1.get(c.ownerid);
         if(s=='System Administrator')
         {
           c.Non_System_Admin_Case__c='yes';
         }
         else
         {
         c.Non_System_Admin_Case__c='No';
         }
           
   
   }
  
}
ch ranjeethch ranjeeth
I know that before insert we won't get record owner id but how to solve this please help me
James LoghryJames Loghry
You should get the OwnerId, but not the Id of the contact itself.  So you should be good in that regard.

I would suggest you start throwing System.debug statements in your code  Start with debugging whether "set1" and "userList" are populated, and then go from there.

Otherwise, it's hard to tell what exactly is happening.

Also, consider changing your "Non_System_Admin_Case__c" field from a Text field to a Checkbox.  A yes/no text field is silly.