Another Salesforce blog!!!

Salesforce, Apex

Salesforce – Making the User Object standard field Unique.

PS: make sure to add

<apex:pageMessages id="pageMsg"/>

on the VFP

trigger ExtesionTrigger on User (before insert , before update)
    Set<String> setExtension = new Set<String>();
    for(User u :
            Boolean isNewExt = setExtension.add(u.Extension);
            //This will ensure that in bulk insert you are not inserting two users with same extension
                u.addError('Dulicate Extension');
    List<User> ul = [Select id from User where Extension in: setExtension];
    if(ul.size() > 0)
  'Dulicate Extension');


Leave a Reply

Your email address will not be published. Required fields are marked *