• RTHawk
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Any help/idea will be more than appreciated! I have a trigger that inserts a new opportunity record once stage is set to closedwon, it works fine until i try to set the newly inserted record to closewon. I get the following error message
 
System.NullPointerException: Attempt to de-reference a null object: Trigger.RenewalOpportunity: line 9, column 48
 
contract_length__c is a number field while contract_activation_date is a date field. below is the code I have so far
 
Trigger
Code:
trigger RenewalOpportunity on Opportunity (after update) {
                        
    for (Integer i = 0; i < Trigger.new.size(); i++) {
               
       if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false && Trigger.new[i].RenewalOpportunity__c == null) {
            
            Opportunity renewalOpp = Trigger.new[i].clone(false);

            Double x = Trigger.old[i].Contract_Length__c;
            Integer y = x.intValue();
            
            renewalOpp.Name = 'Renewal - '+  Trigger.old[i].Name;
            renewalOpp.closedate = Trigger.old[i].Contract_Activation_Date__c.addmonths(y);
            renewalOpp.stagename = '0 - Very Early Stage';
            renewalOpp.probability = 0;
            renewalOpp.ForecastCategoryName = 'Pipeline';
            renewalOpp.Contract_Activation_Date__c = null;
            renewalOpp.Contract_Length__c = null;


            insert renewalOpp;
            
      if (Trigger.old[i].Name.startsWith('Renewal - ')) {
          renewalOpp.Name = Trigger.old[i].Name;
          update renewalOpp;
          }

      if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false && Trigger.new[i].RenewalOpportunity__c == null) {
            Opportunity newOpp = [select ID from Opportunity where id = :Trigger.new[i].ID];
            newOpp.RenewalOpportunity__c = renewalOpp.ID;
            update newOpp;
            }            
      }
   }
}

 
Unit Test
 
Code:
public class CreateOpportunity {

    static testMethod void testCreateOpportunityRenewal(){
    // Test opportunities moving from isWon = false to isWon = true
    try {
        
        Double Contract_Length = 13;
        Double x = Contract_Length;
        Integer y = x.intValue();
        
        Date today = System.today();
        Date contract_activation_date = System.today();
        Date closeDate = contract_activation_date.addmonths(y);
                 
        Opportunity opportunity = new Opportunity();
        
        opportunity.name = 'old opportunity name';
        opportunity.Contract_Length__c = 13;
        opportunity.contract_activation_date__c = today;
        opportunity.closedate = today;
        opportunity.stagename = 'Closed Lost';
        opportunity.probability = 1;
        opportunity.ForecastCategoryName = 'Closed';
                
        insert opportunity;
        
        System.assertEquals(opportunity.name, 'old opportunity name');

        opportunity.stagename = 'Closed Won';
        update opportunity;
        
        Opportunity updatedOpportunity = [select ID,RenewalOpportunity__c from Opportunity where id = :opportunity.ID];
        
        // go get new opportunity
        System.debug('opportunityId: ' + updatedOpportunity.RenewalOpportunity__c);
        Opportunity newOpportunity = [select ID, Name, Contract_Length__c, contract_activation_date__c, closedate, stagename, probability, forecastCategoryName from Opportunity where id = :updatedOpportunity.RenewalOpportunity__c];
        
        System.assertNotEquals(newOpportunity, null);
        
        System.assertEquals(newOpportunity.name, 'Renewal - old opportunity name');
        System.assertEquals(newOpportunity.Contract_Length__c, 12);        
        System.assertEquals(newOpportunity.contract_activation_date__c, today);
        System.assertEquals(newOpportunity.closedate, closeDate);
        System.assertEquals(newOpportunity.stagename, '0 - Very Early Stage');
        System.assertEquals(newOpportunity.probability, 0);
        System.assertEquals(newOpportunity.ForecastCategoryName, 'Pipeline');
        
        delete opportunity;
    }    
    catch (DmlException e) {
        System.assert(false);
    }

    // Test opportunities moving from isWon = false to isWon = false
    try {

        Double Contract_Length = 13;
        Double x = Contract_Length;
        Integer y = x.intValue();
        
        Date today = System.today();
        Date contract_activation_date = System.today();
        Date closeDate = contract_activation_date.addmonths(y);
            
        Opportunity opportunity = new Opportunity();
        opportunity.Contract_Length__c = 13;
        opportunity.contract_activation_date__c = today;
        opportunity.name = 'old opportunity name';
        opportunity.closedate = today;
        opportunity.stagename = 'Closed Lost';
        opportunity.probability = 1;
        opportunity.ForecastCategoryName = 'Closed';

        insert opportunity;
        
        System.assertEquals(opportunity.name, 'old opportunity name');
        
        opportunity.stagename = 'Final Steps';
        update opportunity;
        
        Opportunity updatedOpportunity = [select ID,RenewalOpportunity__c from Opportunity where id = :opportunity.ID];
        try
        {
            Opportunity newOpportunity = [select ID from Opportunity where id = :updatedOpportunity.RenewalOpportunity__c];
            System.assert(false);
        }
        catch (Exception e) {
        }
    
        delete opportunity;
    }    
    catch (DmlException e) {
        System.assert(false);
    }
  }
}

 
Thanks in adavance :)
I've been using the Force.com IDE since it was called the Apex plugin for Eclipse.  Today I had some trouble on it on Eclipse 3.2, so I got a brand new, clean copy of Eclipse 3.3.1.1 and installed it.  I fired up Eclipse 3.3 and installed the Force.com toolkit with its dependency (WST or whatever it was).  Everything seemed to go well.  Eclipse restarted itself.

Upon restart, though, I could see no trace of the Force.com IDE.  There was no way to create an Apex (or Force.com) project.  There is no Force.com perspective.  Everything seems to be MIA.  Meanwhile, if I go up to Help->Manage Configuration, the Force.com IDE is listed there and seems to think that it is installed properly.

I have tried disabling it, cleaning it out and reinstalling, but to no avail -- upon my second installation (which also appeared to go well), there were no Force.com items available upon restart.

What gives here?  Has anyone had this issue before, and if so, how did you fix it?