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
Akarsh SharmaAkarsh Sharma 

write a trigger on contact

“In contact Object we have Contacts status picklist Field when contact user have system administrator profile then he able select active, inactive & disqualify Value as well user have other profile then it only able to select active and in active status”
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Akarsh,

So the requirement is that Other than system admin no other profiles should be able to change the contact Status to "diqualify". if they try ti change it error message should popup?

Thanks,
 
CharuDuttCharuDutt
Hii Akarsh
Try Below Trigger
trigger StatusError on Contact (before insert,before update) {
    
    string profilename = [SELECT Id, Name FROM Profile where Id =:userinfo.getProfileId() ].Name;
    if(trigger.isBefore && (trigger.isInsert || Trigger.IsUpdate)){
        
        for(Contact con : Trigger.new){
            if(profilename != 'System Administrator' && (Con.Status__c != 'Active' || Con.Status__c != 'InActive')){
                con.AddError('Only Syatem Admin Can Select Status Other Than Active And InActive');
            }
        } 
        
    }
    
}
Please Mark It As Best Answer If It Helps
Thank You!
Akarsh SharmaAkarsh Sharma
hi Sai praveen, 
yes, this is  the requirement.
CharuDuttCharuDutt
Hii Akarsh
Try Below Trigger OR Validation Rule
Validation Rule
AND( $Profile.Name <> 'Syatem Administartor', ISPICKVAL(Status__c,'diqualify'))
=================================================================================================================
trigger StatusError on Contact (before insert,before update) {
    
    string profilename = [SELECT Id, Name FROM Profile where Id =:userinfo.getProfileId() ].Name;
    if(trigger.isBefore && (trigger.isInsert || Trigger.IsUpdate)){
        
        for(Contact con : Trigger.new){
            if(profilename != 'System Administrator' && Con.Status__c == 'diqualify'){
                con.AddError('Only Syatem Admin Can Select diqualify Status');
            }
        } 
        
    }
    
}
Please Mark It As Best Answer If It Helps
Thank You!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You can write the trigger on contact as below.
 
trigger ContactStatusError on Contact (before insert,before update) {
string profilename = [SELECT Id, Name FROM Profile where Id =:userinfo.getProfileId() ].Name;
    if(trigger.isBefore && (trigger.isInsert || Trigger.IsUpdate)){
        
        for(Contact con : Trigger.new){
            if(profilename != 'System Administrator' && Con.Contact_Status__c  == 'disqualify '){
                con.AddError('Only System admin can change the contact status to disqualify');
            }
        } 
        
    }
    
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,