• Wachiva
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi

I have written my first trigger and and having some trouble extending it... at present it works fine allocation the correct user to a record based on postal code using a custom object.

My need is to exclude records bing created by certain user roles being affected by this trigger and having experimented with how to do this i have become stuck, any help would be greatly appreciated.

At pressent the trigger is as below

trigger Assignaccounts on Account (After insert, Before Update) {

List <account> accountstoupdate = new list<account>();
for (account newaccount : Trigger.new)

IF (newAccount.Key_Account__c != True)
if (newAccount != null)
if (newaccount.BillingPostalCode != null) 
If (account.BillingPostalCode != NULL)

{List<postcode__c> Postcodes = [ SELECT User__c FROM postcode__c WHERE name LIKE :newaccount.BillingPostalCode.SubString(0,2) + '%' limit 1];
if (postcodes.size()>0)
{newaccount.OwnerId = postcodes[0].User__c;

accountstoupdate.add(newaccount);
}}} 

Thankyou

Andrew
Hi

I have written my first trigger and and having some trouble extending it... at present it works fine allocation the correct user to a record based on postal code using a custom object.

My need is to exclude records bing created by certain user roles being affected by this trigger and having experimented with how to do this i have become stuck, any help would be greatly appreciated.

At pressent the trigger is as below

trigger Assignaccounts on Account (After insert, Before Update) {

List <account> accountstoupdate = new list<account>();
for (account newaccount : Trigger.new)

IF (newAccount.Key_Account__c != True)
if (newAccount != null)
if (newaccount.BillingPostalCode != null) 
If (account.BillingPostalCode != NULL)

{List<postcode__c> Postcodes = [ SELECT User__c FROM postcode__c WHERE name LIKE :newaccount.BillingPostalCode.SubString(0,2) + '%' limit 1];
if (postcodes.size()>0)
{newaccount.OwnerId = postcodes[0].User__c;

accountstoupdate.add(newaccount);
}}} 

Thankyou

Andrew