• Ruben Schmelzer
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
Hi,

need help regariding my trigger below. Get this error code (SOQL does not contain results):

Severity and Description    Path    Resource    Location    Creation Time    Id
System.DmlException: Update failed. First exception on row 0 with id 00620000005uHyQAAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, simpleTrigger02: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.simpleTrigger02: line 77, column 61    SFDC_Ph01_deploy_Renewal_Trigger/src/unpackaged/classes    simpleTrigger02testClass03.cls    line 138    1220262381688    2940

Question: Red marked code is causing error (below: Oli1). Why does APEX does not find my Opportunity ID? The log tells me that oppty1.id and oppty2.id is existing!
 
CODE:

trigger simpleTrigger02 on Opportunity (after update) {
    
    OpportunityLineItem oli1 =                         new OpportunityLineItem();
    OpportunityLineItem oli2 =                         new OpportunityLineItem();
    OpportunityLineItem oli3 =                         new OpportunityLineItem();
    OpportunityLineItem oli4 =                         new OpportunityLineItem();
    
    Opportunity oppty2 =                                  new Opportunity();
    Opportunity oppty3 =                                  new Opportunity();
    Opportunity oppty4 =                                  new Opportunity();
            
    List<OpportunityLineItem> oliList2 =         new List<OpportunityLineItem>();
     List<OpportunityLineItem> oliList3 =        new List<OpportunityLineItem>();
     List<OpportunityLineItem> oliList4 =        new List<OpportunityLineItem>();
     List<OpportunityLineItem> oliListX =        new List<OpportunityLineItem>();
     
     List<Opportunity> T_new =                      Trigger.new;
     ID oid1 =                                                    T_new.get(0).id;
     
     List<Opportunity> T_old =                        Trigger.old;
     ID oid2 =                                                    T_old.get(0).id;
          
    for (Opportunity oppty1 : Trigger.new){
                             
        if (oppty1.renew__c == true){
                                 
            for (Opportunity opptytest1 : Trigger.old) {
                                       
            Double cdate =                                                oppty1.RenewalTermCalcDouble__c;
            Integer i =                                                         cdate.intValue();
                            
            oppty2.accountid =                                                         oppty1.accountid;
            oppty2.CustomerOrderDate__c =                                 oppty1.CustomerOrderDate__c;
            oppty2.CustomerOrderedBy_del__c =                          oppty1.CustomerOrderedBy_del__c;
            oppty2.CustomerOrderID__c =                                      oppty1.CustomerOrderID__c;
            oppty2.CustomerOrderNumberAdditonal__c =              oppty1.CustomerOrderNumberAdditonal__c;
            oppty2.DateOfDelivery__c =                                             oppty1.DateOfDelivery__c;
            oppty2.Description =                                                         'Angelegt am: ' + dit.addhours(2);
            oppty2.GMDRetention__c =                                             oppty1.GMDRetention__c;
            oppty2.OpportunityInitial__c  =                                         oppty1.id;
            oppty2.InvoiceDate__c =                                                 oppty1.InvoiceDate__c;
            oppty2.name =                                                                    'Renewal 1.Jahr';
             oppty2.OwnerId =                                                             oppty1.OwnerId;
            oppty2.Pricebook2Id =                                                     oppty1.Pricebook2Id;
            oppty2.Probability =                                                         oppty1.Probability;
            oppty2.Product__c =                                                         oppty1.Product__c;
            oppty2.ProductOther__c =                                                 oppty1.ProductOther__c;
            oppty2.RecordTypeId =                                                     '012200000000ZErAAM';
            oppty2.Type =                                                                     'Renewal';
            oppty2.RenewalTerm__c =                                                 oppty1.RenewalTerm__c;
            oppty2.RenewalType__c =                                                    oppty1.RenewalType__c;
            oppty2.RequirementsDescription__c =                                 oppty1.RequirementsDescription__c;
            oppty2.StageName =                                                              'Renewal Open';
             oppty2.Service__c =                                                             oppty1.Service__c;              
            oppty2.CloseDate =                                                                 oppty1.CloseDate.addMonths(12);
         
             System.debug('DIE OPPTY1.ID:                     **********************' + oppty1.id);                          
            
            oli1.opportunityId =                             oppty1.id;
            oli1.quantity =                                 200.0;
             oli1.unitprice =                                 20.0;
             oli1.PricebookEntryId =                         '01u20000000fK10AAE';    
             
             oliListX.add(oli1);
            /*
            insert oliList2;
            */
            
            oli1 =                                             [Select quantity, unitprice, pricebookentryid, opportunityid from OpportunityLineItem where PricebookEntry.product2.ActivateRenewal__c =                                                                     TRUE AND PriceBookEntryID <> '01u20000000fK11AAE' AND OpportunityID = :oppty1.id limit 1];                                          
          insert oppty2;
                
          System.debug('OPPTY1.ID:                 **********************' + oppty1.id);                          
          System.debug(' OPPTY2.ID:                 **********************' + oppty2.id);                          
                            
                 oli2.opportunityId =                         oppty2.id;
                 oli2.quantity =                             oli1.quantity;
                 oli2.unitprice =                             oli1.unitprice;
                 oli2.pricebookentryid =                     oli1.pricebookentryid;
                 
                 oliList2.add(oli2);     
                         
                  insert oliList2;
                                 
            }
        }
        
    }
}