You need to sign in to do that
Don't have an account?
Chris Grover
How can i fix the data type issue between integer and decimal when using dates in a calculation
I cannot resolve this error'Date expressions must use Integer or Long (8:45)'
trigger WarrantySummary on Case (before insert) {
for (Case myCase : Trigger.new){
// Set up variables to use in the summary field
Date purchaseDate = myCase.Product_Purchase_Date__c;
Datetime createdDate = myCase.CreatedDate;
Integer warrantyDays = myCase.Product_Total_Warranty_Days__c.intValue();
Decimal warrantyPercentage = purchaseDate.daysBetween(Date.today()) / warrantyDays;
Boolean hasExtendedWarranty = myCase.Product_Has_Extended_Warranty__c;
//Populate summary field
myCase.Warranty_Summary__c = 'Product Purchased on ' + purchaseDate + ' '
+ 'and case created on ' + createdDate + '.\n'
+ 'Warranty is for ' + warrantyDays + ' '
+ 'and is ' + warrantyPercentage +'% through its warranty period.\n'
+ 'Extended warranty: ' + hasExtendedWarranty + '\n'
+ 'Have a nice day!';
}
}
trigger WarrantySummary on Case (before insert) {
for (Case myCase : Trigger.new){
// Set up variables to use in the summary field
Date purchaseDate = myCase.Product_Purchase_Date__c;
Datetime createdDate = myCase.CreatedDate;
Integer warrantyDays = myCase.Product_Total_Warranty_Days__c.intValue();
Decimal warrantyPercentage = purchaseDate.daysBetween(Date.today()) / warrantyDays;
Boolean hasExtendedWarranty = myCase.Product_Has_Extended_Warranty__c;
//Populate summary field
myCase.Warranty_Summary__c = 'Product Purchased on ' + purchaseDate + ' '
+ 'and case created on ' + createdDate + '.\n'
+ 'Warranty is for ' + warrantyDays + ' '
+ 'and is ' + warrantyPercentage +'% through its warranty period.\n'
+ 'Extended warranty: ' + hasExtendedWarranty + '\n'
+ 'Have a nice day!';
}
}
* I am assuming field(Product_Total_Warranty_Days__c)'s Datatype is Number then Please use below code:
Trigger--->
* If field(Product_Total_Warranty_Days__c)'s Datatype is Date then change code's line
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
All Answers
* I am assuming field(Product_Total_Warranty_Days__c)'s Datatype is Number then Please use below code:
Trigger--->
* If field(Product_Total_Warranty_Days__c)'s Datatype is Date then change code's line
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Decimal warrantyPercentage = 100*(purchaseDate.daysBetween(Date.today()) / myCase.Product_Total_Warranty_Days__c);
Thank you for your help!
I've gone through your requirement and you can typecast the decimal value into integer and vice-versa,see the example below:
1.Decimal to Integer:
Decimal dValue = 7.3;
Integer intConvertedValue = dValue.intValue();
2.Integer to Decimal:
Integer IntegerValue = 7;
Decimal DecConvertedValue = Decimal.valueOf(IntegerValue);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com