• RustyThunder
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I am new to this, so please bear with me ...

 

I am trying to setup a trigger that will automatically populate the product of a case if a support tech enters a serial number, but if there is no serial number, leave the product field alone for the tech to use normally.

 

Within the Case object, I have the field Product (Product__c) which is a type Lookup(Product) and I have a field Serial Number (Serial_Number__c) which is a type Lookup(Asset).  (Our assets' names are the same as the serial numbers)

 

Under the Asset object, I have a the standard field of Product (Product2) which is a type Lookup(Product).

 

I want the trigger to run after insert and after update.  Essentially I want it to check the case to see if there is a Serial Number and if so, use the Product defined within the Asset (Serial Number).  This way I will not have issues where we get the Serial Number later, enter it in and have the wrong product on the case.

 

Below is my meager code, I know I am not doing something right as it is giving me a compile error on the where clause that I put in.  I don't think it is the right way to do it.

 

Thanks.

 

trigger updateProduct on Case (after insert, after update) {

Case myCase = trigger.new[0];
if (myCase.Serial_Number__c) {myCase.Product__c = Asset.Product2.Name where Asset.Name = myCase.Serial_Number__c; update myCase;}

}

 

I am new to this, so please bear with me ...

 

I am trying to setup a trigger that will automatically populate the product of a case if a support tech enters a serial number, but if there is no serial number, leave the product field alone for the tech to use normally.

 

Within the Case object, I have the field Product (Product__c) which is a type Lookup(Product) and I have a field Serial Number (Serial_Number__c) which is a type Lookup(Asset).  (Our assets' names are the same as the serial numbers)

 

Under the Asset object, I have a the standard field of Product (Product2) which is a type Lookup(Product).

 

I want the trigger to run after insert and after update.  Essentially I want it to check the case to see if there is a Serial Number and if so, use the Product defined within the Asset (Serial Number).  This way I will not have issues where we get the Serial Number later, enter it in and have the wrong product on the case.

 

Below is my meager code, I know I am not doing something right as it is giving me a compile error on the where clause that I put in.  I don't think it is the right way to do it.

 

Thanks.

 

trigger updateProduct on Case (after insert, after update) {

Case myCase = trigger.new[0];
if (myCase.Serial_Number__c) {myCase.Product__c = Asset.Product2.Name where Asset.Name = myCase.Serial_Number__c; update myCase;}

}