Update reps table with right values in a trigger after insert on userterritory
I edited your TRIGGER to do this:


I added the vTerritoryCount variable.
If you have more than 1 rows with the same userid it wont update the reps.territories_id.


Here's the TRIGGER:

USE `veeva_new`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` TRIGGER `veeva_new`.`userterritory_ai` AFTER INSERT ON `userterritory` FOR EACH ROW
BEGIN
    # [ VARIABLES DECLARATION ]
    DECLARE vUserID VARCHAR(18) DEFAULT '';
    DECLARE vTerritoryRep VARCHAR(45) DEFAULT '';
    DECLARE vTerritoryLastMod DATETIME DEFAULT '0000-00-00 00:00:00';
    DECLARE vTerritoryCount INT(7) DEFAULT 0; #[060715.01]
    # [ VARIABLES ASIGNATION ]
    SET vUserID         =NEW.userid;
    SET vTerritoryRep   =(SELECT IFNULL(reps.territories_id,'N/A') FROM pdone.reps WHERE reps.veeva_rep_id=vUserID LIMIT 0,1);
    SET vTerritoryLastMod=(SELECT reps.lastSyncAt FROM pdone.reps WHERE reps.veeva_rep_id=vUserID LIMIT 0,1);
    SET vTerritoryCount =(SELECT COUNT(*) FROM veeva_new.userterritory WHERE userterritory.userid=vUserID);
IF (NEW.territoryid != vTerritoryRep) THEN # [ IF THE NEW TERRITORYID IS DIFFERENT FROM TERRIROTYID IN reps TABLE ]
    IF (vTerritoryCount&gt;1) THEN
        SET @Blah='There\'s more than 1 rows, I\'m not going to do anything.';
    ELSE
        UPDATE pdone.reps 
        SET reps.territories_id = NEW.territoryid, 
            reps.lastSyncAt = IF(NOW()&gt;vTerritoryLastMod,NOW(),reps.lastSyncAt), 
            reps.updatedAt=now() 
        WHERE reps.veeva_rep_id=vUserID;
    END IF;
END IF;
END