• gowtham kumar 14
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi all,

 I have to query to get the record count in objcet which is older than 2015 year. please help me with this .
Trigger TerritoryOwnerRestrictionTrigger on Territory__c (after insert,before Update) {
    for (Territory__c T : Trigger.new)
    {
       
      Integer i = [Select count() from Territory__c where Territory__c.OwnerId !=:T.OwnerId and Territory__c.Id !=: T.Id and Territory__c.Name=:T.Name];
        System.debug('Count :'+i);
      if(i>2)
      {
         T.addError('we can not Assign a zipcode to this user, Only a single zipcode is assigned to only three Owners.'); 
      }
    }
}
Field NameField TypeDescription
Previous OwnerLookup (User)The prior sales rep assigned to this Account
New OwnerLookup (User)The new sales rep assigned to this Account
Previous TerritoryLookup (Territory__c)The matching Territory__c record for the prior zip code
New TerritoryLookup (Territory__c)The matching Territory__c record for the new zip code
AccountMaster-Detail (Account)The related Account record
Changed ByLookup (User)The user who changed the BillingPostalCode