• Ceza
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all
 
I'm having trouble with an Apex trigger that I've created. I used the leadDuplicatePreventer trigger in the Force.com cookbook and edited to involve checking a user alias is unique. When I edited this in my Sandbox environment it worked correctly and I had no problem. Now I'm trying to implement this into my Production environment via Eclipse and I seem to be running into trouble. 1st of all I get an error message that the test coverage is 0% (despite being working in Sandbox) and 2nd when I have tried to edit the trigger to active and I receive messages that the trigger is only saved locally, not to server. How come this happens? Why does it work on Sandbox and not on the Production environment?
 
The code ;)

trigger UserAliasDuplicatePreventer on User (before insert, before update)

{Map<String, User> userMap = new Map<String, User>();

for (User user : System.Trigger.new)

{if ((user.Alias != null) && (System.Trigger.isInsert || (user.Alias != System.Trigger.oldMap.get(User.Id).Alias)))

{if (userMap.containsKey(user.Alias))

{user.Alias.addError('Another new user has the same alias.');}

else {userMap.put(user.Alias, user);}}}

for (User user : [SELECT Alias FROM User WHERE Alias IN :userMap.KeySet()])

{User newUser = userMap.get(user.Alias);newUser.Alias.addError('A user already has this alias.');}}

 
  • April 01, 2008
  • Like
  • 0
Hi all
 
I'm having trouble with an Apex trigger that I've created. I used the leadDuplicatePreventer trigger in the Force.com cookbook and edited to involve checking a user alias is unique. When I edited this in my Sandbox environment it worked correctly and I had no problem. Now I'm trying to implement this into my Production environment via Eclipse and I seem to be running into trouble. 1st of all I get an error message that the test coverage is 0% (despite being working in Sandbox) and 2nd when I have tried to edit the trigger to active and I receive messages that the trigger is only saved locally, not to server. How come this happens? Why does it work on Sandbox and not on the Production environment?
 
The code ;)

trigger UserAliasDuplicatePreventer on User (before insert, before update)

{Map<String, User> userMap = new Map<String, User>();

for (User user : System.Trigger.new)

{if ((user.Alias != null) && (System.Trigger.isInsert || (user.Alias != System.Trigger.oldMap.get(User.Id).Alias)))

{if (userMap.containsKey(user.Alias))

{user.Alias.addError('Another new user has the same alias.');}

else {userMap.put(user.Alias, user);}}}

for (User user : [SELECT Alias FROM User WHERE Alias IN :userMap.KeySet()])

{User newUser = userMap.get(user.Alias);newUser.Alias.addError('A user already has this alias.');}}

 
  • April 01, 2008
  • Like
  • 0