You need to sign in to do that
Don't have an account?
Trigger code for Decimal not working please help
I am having a really hard time with one piece of code. I have created a class to take incoming emails and create a case. A trigger will fire before insert that reads the email and updates fields in the case with the appropriate values. I have every field working but a field for Order Amount. For some reason it will not accept the code because it is a decimal field. I even changed the field properties to number without decimals and I still get he same error.
Here is the code:
private String ORDERAMOUNT_TXT = 'Order Amount:';
integer OrderAmountMatchIdx = c.Description.indexOf( ORDERAMOUNT_TXT );
string OrderAmount_Value = c.Description.substring( OrderAmountMatchIdx + ORDERAMOUNT_TXT.length() );
c.Order_Amount__c = OrderAmount_Value;
Error: Compile Error: Illegal assignment from String to Decimal at line 32 column 1 |
Please help because I am out of ideas.
You're assigning a String value to a Decimal variable. Apex is strongly typed and won't allow you to do this.
(c.Order_Amount__c = OrderAmount_Value;)
Make this :
c.Order_Amount__c = Decimal.valueOf(OrderAmount_Value);
That ought to do it.
David
All Answers
You're assigning a String value to a Decimal variable. Apex is strongly typed and won't allow you to do this.
(c.Order_Amount__c = OrderAmount_Value;)
Make this :
c.Order_Amount__c = Decimal.valueOf(OrderAmount_Value);
That ought to do it.
David
So simple... :smileyvery-happy: I was almost going to try that.
Thank you!!
Ok along those same lines I am getting an error with the following code:
integer EmailAddressMatchIdx = c.Description.indexOf( EMAILADDRESS_TXT );
string EmailAddress_Value = c.Description.substring( EmailAddressMatchIdx + EMAILADDRESS_TXT.length() );
c.Consumer_Contact_Email__c = EmailAddress_Value;
integer IPAddressMatchIdx = c.Description.indexOf( IPADDRESS_TXT );
string IPAddress_Value = c.Description.substring( IPAddressMatchIdx + IPADDRESS_TXT.length() );
c.IP_Address__c = IPAddress_Value;
integer Address1MatchIdx = c.Description.indexOf( ADDRESS1_TXT );
string Address1_Value = c.Description.substring( Address1MatchIdx + ADDRESS1_TXT.length() );
c.Address_1__c = Address1_Value;
integer Address2MatchIdx = c.Description.indexOf( ADDRESS2_TXT );
string Address2_Value = c.Description.substring( Address2MatchIdx + ADDRESS2_TXT.length() );
c.Address_2__c = Address2_Value;
This is the error that I am getting:
>>> cs_tools@d-2ip80vhgddefok4cnbidggn93.in.sandbox.salesforce.com
>>> (Undelivered): 554 System.DmlException: Insert failed. First
>>> exception on row 0; first error:
>>> CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CheckFieldValues: data changed
>>> by trigger for field Consumer Contact Email: invalid email address:
>>> sarah.mccarthy@ymail.com | Address 1: (Senders address) | Address
>>> 2: (Recipient Address) | End:End | this is the actual test of the
>>> script Class.cases.handleInboundEmail: line 41, column 1