• Dipil Jain
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi All,

i'm new to apex code. I'm trying to update the fields Pending_Activation_Date__c and Pending_Deactivation_Date__c on the Order__c object using a trigger. my Asset object has a reference to Order_Line_Item__c object which in-turn has a reference to Order__c object. the trigger is firing on update of Asset Object. below is the trigger code from eclipse IDE.

trigger UpdateOrder on Asset (Before Update) {
    Order_Line_Item__c tempOrderLine;
    Order__c tempOrder, OrderToUpdate;
   
if(trigger.isBefore)
    {
     System.debug('Inside UpdateOrder');
        //It will update the pending Activation and pending deactivation picklists on order object
        for(Asset astObj : trigger.new)
        {
         System.debug('Processing Asset Id '+astObj.id);
         tempOrderLine = [select order_line_item__r.id from Asset where Asset.Id =: astObj.Id limit 1];
         System.debug('Corresponding Order Line Item '+tempOrderLine.Name);
         tempOrder= [select order__r.id from Order_Line_Item__c where id =: tempOrderLine.id limit 1];
         System.debug('Corresponding Order '+tempOrder.Name);
         OrderToUpdate = [select Pending_Activation_Dates__c, Pending_Deactivation_Dates__c from Order__c where order__c.id=:tempOrder.Id limit 1];
         if(astObj.ActivationDate__c!=null){
          tempOrder.Pending_Activation_Dates__c='M6 Effective From Dates';
         }
         if(astObj.UsageEndDate!=null){
          tempOrder.Pending_Deactivation_Dates__c='M6 Effective To Dates';
         }
        }
        if(OrderToUpdate.Id!=null){
         update OrderToUpdate;
        }
       
    }
}

but Eclipse is keep showing error of Save error: Illegal assignment from LIST<Asset> to SOBJECT:Order_Line_Item__c
on this line.
tempOrderLine = [select order_line_item__r.id from Asset where Asset.Id =: astObj.Id limit 1];

now Since this line is inside the for loop, the asset object should not be a list, it can always be a single object from the list of Asset objects from Trigger. not sure why this error is coming. can you please help me... also this trigger is firing but no lines are executing. below is the debug log for its firing sequence.

01:07:41.140 (140215573)|EXECUTION_STARTED
01:07:41.140 (140248778)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
01:07:41.140 (140279864)|CODE_UNIT_STARTED|[EXTERNAL]|01qL00000004Y3K|UpdateOrder on Asset trigger event BeforeUpdate for [02iL00000003pZF]
01:07:41.010 (141930232)|CUMULATIVE_LIMIT_USAGE
01:07:41.010|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

01:07:41.010|CUMULATIVE_LIMIT_USAGE_END

01:07:41.142 (142006686)|CODE_UNIT_FINISHED|UpdateOrder on Asset trigger event BeforeUpdate for [02iL00000003pZF]

Your help is greatly appreciated. Thanks!

Regards,
Dipil Jain
Hi All,

i'm new to apex code. I'm trying to update the fields Pending_Activation_Date__c and Pending_Deactivation_Date__c on the Order__c object using a trigger. my Asset object has a reference to Order_Line_Item__c object which in-turn has a reference to Order__c object. the trigger is firing on update of Asset Object. below is the trigger code from eclipse IDE.

trigger UpdateOrder on Asset (Before Update) {
    Order_Line_Item__c tempOrderLine;
    Order__c tempOrder, OrderToUpdate;
   
if(trigger.isBefore)
    {
     System.debug('Inside UpdateOrder');
        //It will update the pending Activation and pending deactivation picklists on order object
        for(Asset astObj : trigger.new)
        {
         System.debug('Processing Asset Id '+astObj.id);
         tempOrderLine = [select order_line_item__r.id from Asset where Asset.Id =: astObj.Id limit 1];
         System.debug('Corresponding Order Line Item '+tempOrderLine.Name);
         tempOrder= [select order__r.id from Order_Line_Item__c where id =: tempOrderLine.id limit 1];
         System.debug('Corresponding Order '+tempOrder.Name);
         OrderToUpdate = [select Pending_Activation_Dates__c, Pending_Deactivation_Dates__c from Order__c where order__c.id=:tempOrder.Id limit 1];
         if(astObj.ActivationDate__c!=null){
          tempOrder.Pending_Activation_Dates__c='M6 Effective From Dates';
         }
         if(astObj.UsageEndDate!=null){
          tempOrder.Pending_Deactivation_Dates__c='M6 Effective To Dates';
         }
        }
        if(OrderToUpdate.Id!=null){
         update OrderToUpdate;
        }
       
    }
}

but Eclipse is keep showing error of Save error: Illegal assignment from LIST<Asset> to SOBJECT:Order_Line_Item__c
on this line.
tempOrderLine = [select order_line_item__r.id from Asset where Asset.Id =: astObj.Id limit 1];

now Since this line is inside the for loop, the asset object should not be a list, it can always be a single object from the list of Asset objects from Trigger. not sure why this error is coming. can you please help me... also this trigger is firing but no lines are executing. below is the debug log for its firing sequence.

01:07:41.140 (140215573)|EXECUTION_STARTED
01:07:41.140 (140248778)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
01:07:41.140 (140279864)|CODE_UNIT_STARTED|[EXTERNAL]|01qL00000004Y3K|UpdateOrder on Asset trigger event BeforeUpdate for [02iL00000003pZF]
01:07:41.010 (141930232)|CUMULATIVE_LIMIT_USAGE
01:07:41.010|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

01:07:41.010|CUMULATIVE_LIMIT_USAGE_END

01:07:41.142 (142006686)|CODE_UNIT_FINISHED|UpdateOrder on Asset trigger event BeforeUpdate for [02iL00000003pZF]

Your help is greatly appreciated. Thanks!

Regards,
Dipil Jain