function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amyhamyh 

My First Trigger attempt and its error message

Hello,

I'm  trying to create my first trigger, but I get the error message:
Save error: Comparison arguments must be compatible types: Schema.SObjectField, Boolean   

What I'm trying to accomplish is to automatically generate a case when a user checks a box
on the Sales Order Line Item page.

Below is my attempt, and the error is on line 5.

I would greatly appreciate any help or direction.

thanks!!



trigger CreateCaseAfterShippingConfirmsOrder on SFDC_520_QuoteLine__c
(after update)

{       
    if (SFDC_520_QuoteLine__c.Shipping_Confirms_Order__c == True)
    {
              Case newCase = new Case(
                Subject = 'New Data Production Project',
                Status = 'Not Started',
                Product__c = 'XXX One (2.0)',
                Priority = 'Sev-4 (when resources allow)',
                Origin = 'Web' 
                );
                insert newCase;
    }
    else
    {
    }           
}
JeremyKraybillJeremyKraybill
This is occurring because your code is operating on the object definition, not the actual triggered instances themselves. Try changing it to this:

Code:
trigger CreateCaseAfterShippingConfirmsOrder on SFDC_520_QuoteLine__c
(after update)

{       
    for (SFDC_520_QuoteLine__c obj : Trigger.new) {
        if (obj.Shipping_Confirms_Order__c == True) {
              Case newCase = new Case(
                Subject = 'New Data Production Project',
                Status = 'Not Started',
                Product__c = 'XXX One (2.0)',
                Priority = 'Sev-4 (when resources allow)',
                Origin = 'Web' 
                );
                insert newCase;
        }
    }           
}

That should work.
amyhamyh
Thank you for the quick reply. It compiles now!

Thank you very much for your time.
amyhamyh
Jeremy,

Can I ask you how I go about creating the test class (assuming that's what I need
to do, since I can't seem to deploy my new trigger), and how do I actually run the test.
I've been round and round, but no luck.

Thank you very much!
JeremyKraybillJeremyKraybill
Yes, you need 75% line coverage. See the "Debugging Apex" chapter of the dev reference, in the section "Testing and Code Coverage." HTH.

http://www.salesforce.com/us/developer/docs/apexcode/index.htm

jk