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
mba75mba75 

Convert object to double use newvalue in history

Illegal assignment from Object to Double
 

 for (OpportunityLineItem oli : [SELECT Margin_Percentage__c, Margin_Amount__c, PriceBookEntry.Id, PricebookEntry.Product2Id,PricebookEntry.product2.id,
  PricebookEntry.product2.Service_Line__c FROM OpportunityLineItem WHERE Opportunityid in :oppnew]) {    
    
    Product_Service_Lines__history PSL= [Select NewValue From Product_service_lines__history
WHERE Field='Margin_percent__c'
AND Createddate < :CD
AND ParentId=:oli.PricebookEntry.product2.Service_Line__c
ORDER BY Createddate desc
LIMIT 1];

oli.Margin_Percentage__c=PSL.NewValue;

I get the following error message : Illegal assignment from Object to Double


How I can use this newvalue field to track old value

Ron HessRon Hess
Code:
 contacthistory c =[Select c.OldValue, c.NewValue, c.IsDeleted, c.Id, c.Field, c.CreatedDate, 
   c.CreatedById, c.ContactId From ContactHistory c limit 1];
   double dd = double.valueof(c.newvalue);

 

I didn't have your custom object, but was able to cast this anyType to double using double.valueof()