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
Scapelli77Scapelli77 

Eclipse & Trigger

Hi,i have just develope my first trigger, bu i cannot deploy it in to Unlimited Edition, why?
When i try to deploy the trigger, Eclipse failure the coverage test...

this is my trigger:

 trigger PaymentTerm on Opportunity (before insert, before update) {
   Opportunity[] MyOp = Trigger.
new;
   for (Opportunity p:MyOp){
       if (p.Description != 'World') {
           p.Description = 'World';
          }

      }
    }

thanks

Simone

mikefmikef
You just need to write a testMethod in a class that inserts and updates an oppty.

Examples are in the Apex docs under the Testing and Code Coverage section, page 214.


Scapelli77Scapelli77
Hi,
yes i known "testMethod" but in this case i haven't a class it is only a trigger.
 
In my develope org it work but when i whant deploy it with Eclipse in a Unlimited org the deploy process failure..
 
Simone
somasoma
It's my understanding that you are also required to have at least 75% code coverage for triggers, as well.
Ron HessRon Hess
here is a test method for your trigger, note: this is a class
when you run tests on this class it also tests your trigger
Code:
public class testOpp {
 public static testmethod void t1() {
  Opportunity op = new Opportunity();
  op.name = 'tst';
  // more required fields here
  insert op; 
 }
}

 

Scapelli77Scapelli77

Thanks,
with your code i can deploy my trigger.... but is very necessary a class if my trigger don't need a class?

Now I have an other problem, this is my trigger:

trigger PaymentTerm on Opportunity (before insert, before update) {

Opportunity[] MyOp = Trigger.new;

for (Opportunity p:MyOp){
 if (p.PaymentTerm__c == null) {
    p.PaymentTerm__c=[select Terms_of_Payment__c from Account where Id = :p.AccountId];
    }
}
}

if field PaymentTerm__c =null I want update it whit the field Terms_of_Payment__c of Opportunity Account.
 
When I save this code Eclipse return: "Save error: Illegal assignment from LIST:SOBJECT:Account to String"
 
Can you help me?
 
thanks
Simone
Ron HessRon Hess
the documentation explains how to get a list of sobjects from SOQL, and how to access members of that object

would look something like this

p.PaymentTerm__c=[select Terms_of_Payment__c from Account where Id = .AccountId limit 1].Terms_of_Payment__c;



Note, your trigger will bread if bulk loading of opportunities is run as it will hit DML limits since it makes a query for each record.  There are a few posts and articles on Bulk processing, please review these for a general solution.