Trigger is failing with no errors at all, why? I need to UPDATE territory_id column at pdone.reps table by using and filtering results from veeva_new.userterritory so based on the answer I got here I am trying to build my own and this is how it looks like:

USE `veeva_new`;

DELIMITER $$

DROP TRIGGER IF EXISTS veeva_new.userterritory_ai$$
USE `veeva_new`$$
    CREATE DEFINER=`root`@`%` TRIGGER `veeva_new`.`userterritory_ai` AFTER INSERT ON `userterritory` FOR EACH ROW
    BEGIN
    SET @TerritoryVerification=(select reps.veeva_rep_id from pdone.reps where reps.veeva_rep_id=NEW.userid);

    IF (@TerritoryVerification&gt;0) THEN
        SET @TerritoryLastMod=(SELECT reps.lastSyncAt FROM pdone.reps WHERE reps.veeva_rep_id=NEW.userid LIMIT 0,1); 

        IF (NEW.lastmodifieddate &gt; @TerritoryLastMod) THEN
            UPDATE pdone.reps 
            SET reps.territories_id = NEW.territoryid, reps.lastSyncAt = NEW.lastmodifieddate, reps.updatedAt=now() 
            WHERE reps.veeva_rep_id=NEW.userid; 
        END IF;
    END IF;
    END$$
DELIMITER ;


But it's not working since insertion on veeva_new DB just stop with no errors, I just see this in general.log:

 11 Query COMMIT
           11 Query SELECT sync_time FROM _sync_history WHERE object_name='userterritory' ORDER BY sync_time DESC LIMIT 1
150703 12:48:42    11 Query START TRANSACTION
           11 Query INSERT INTO _sync_history (object_name, sync_time) VALUES('userterritory', '2015-07-03 17:18:26')
           11 Query INSERT INTO userterritory (id,lastmodifieddate,userid,territoryid) VALUES('04S80000000uZi9EAE','2009-08-24 17:56:49','00580000001sYARAA2','04T800000008yHOEAY'),('04S80000000uoFIEAY','2009-09-24 19:20:02','00580000002Ka2yAAC','04T800000008yHOEAY')$
           11 Query SET @UserVerification=(select reps.veeva_rep_id from pdone.reps where reps.veeva_rep_id=NEW.userid)
           11 Query ROLLBACK
           11 Quit


This is the schema for veeva_new.userterritory table:

CREATE TABLE `userterritory` (
  `id` varchar(18) NOT NULL,
  `userid` varchar(18) DEFAULT NULL,
  `territoryid` varchar(18) DEFAULT NULL,
  `lastmodifieddate` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


reps.territories_id has a constraint against reps.territories and this is the schema for reps.territories table:

CREATE TABLE `territories` (
  `veeva_territory_id` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
  `district` int(11) DEFAULT NULL,
  `inactive` tinyint(1) NOT NULL,
  `createdAt` datetime NOT NULL,
  `updatedAt` datetime NOT NULL,
  PRIMARY KEY (`veeva_territory_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


What is wrong on my trigger?
Try with: 

USE `veeva_new`;

DELIMITER $$

DROP TRIGGER IF EXISTS veeva_new.userterritory_ai$$
USE `veeva_new`$$
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 vTerritoriRep VARCHAR(45) DEFAULT '';
    DECLARE vTerrytoriLastMod DATETIME DEFAULT '0000-00-00 00:00:00';
    # [ VARIABLES ASIGNATION ]
    SET vUserID         =NEW.userid;
    SET vTerritoriRep   =(select IFNULL(reps.territories_id,'N/A') from pdone.reps where reps.veeva_rep_id=vUserID LIMIT 0,1);
    SET vTerrytoriLastMod=(SELECT reps.lastSyncAt FROM pdone.reps WHERE reps.veeva_rep_id=vUserID LIMIT 0,1);

IF (NEW.territoryid != vTerritoriRep) THEN
    UPDATE pdone.reps 
    SET reps.territories_id = NEW.territoryid, 
        reps.lastSyncAt = IF(NOW()&gt;vTerrytoriLastMod,NOW(),reps.lastSyncAt), 
        reps.updatedAt=now() 
    WHERE reps.veeva_rep_id=vUserID; 
END IF;

END$$
DELIMITER ;


Assuming veeva_rep_id = NEW.userid (from userterritory).

This will update reps.territories_id when the NEW.territoryid is updated, reps.lastSyncAt when reps.lastSyncAt be greater than @TerritoryLastMod and reps.updatedAt = now(), current timestamp.