• Cruzy
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi, I have recently started using Apex triggers with little knowledge of Java before hand and brief history of using visual basic to a moderate level.

 

I am trying to create an Apex trigger to fire when a contract is coming up to expire (I have created a workflow that sets a custom checkbox on contracts to flag it as expiring and am planning to fire it from this). So far I have come up with this, any help would be most appreciated:

 

 

trigger CreateNewOpp on Contract (after update, after insert) {


If (Contract.Contract_Renewal__c = true) {
List <Opportunity> OpportunityToInsert = new List <opportunity> ;
If (Contract.Contract_Renewal__c = true) {
For (Contract C : Trigger.new) {
Opportunity O = new Opportunity () ;
o.accountID = c.accountID ;
o.name = c.name && ' - Renewal' ;
o.ownerid = c.ownerid ;
o.stagename = 'Prospecting' ;
o.closedate = c.Expiration_Of_Contract__c + '365' ;
}
OpportunityToInstert.add (o) ;
}

try {
insert OpportunityToInseret;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
}

  • April 25, 2013
  • Like
  • 0

Who has experience with this app? I am using it to sychronize opportunity product custom fields with quote item custom fields. It works fine however I as soon as the custom fields work with default values, validation rules, workflows I get error messages...  Can anybody help? - Thanks in advance. Reto