You need to sign in to do that
Don't have an account?

Why am I getting this error message? Compile Error: Variable does not exist: BTLog at line 16 column 33
Hello,
I'm new to Salesforce Apex. I keep getting this error message when I try save my code eventhough I've declared the variable already..

Compile Error: Variable does not exist: BTLog at line 16 column 33
I'm trying to build a trigger that create a weight reading records (Bodytrace_Weight__c) based of weight logs records (Bodytrace_Weight__c). After that I'd like to auto-assign (Bodytrace_Weight__c) to the patient who got weighted based on the serial number that is found on both; account object and Bodytrace_Weight__c object.
Please let me know what's the best way to build this. Thanks!
I'm new to Salesforce Apex. I keep getting this error message when I try save my code eventhough I've declared the variable already..
Compile Error: Variable does not exist: BTLog at line 16 column 33
Trigger AutocreateBTWeightRecordsAndMatchitToAccount on bodytrace__c (after insert) { for (BodyTrace__c BTLog : Trigger.new) { Bodytrace_weight__c BTWeight = new Bodytrace_Weight__c(); BTWeight.IMEI__c = BTLog.IMEI__c; BTWeight.Weight__c = BTLog.Values_weight__c; BTWeight.Date_of_reading__c = BTLog.CreatedDate; BTWeight.bodytrace_log__c = BTLog.ID; Insert BTWeight; } For (Account Accnt : Trigger.new) { if(accnt.IMEI__c == BTLog.IMEI__c){ BTWeight.Account__c = account.ID; } } }Background on what I'm trying to do:
I'm trying to build a trigger that create a weight reading records (Bodytrace_Weight__c) based of weight logs records (Bodytrace_Weight__c). After that I'd like to auto-assign (Bodytrace_Weight__c) to the patient who got weighted based on the serial number that is found on both; account object and Bodytrace_Weight__c object.
Please let me know what's the best way to build this. Thanks!
All Answers
If IMEI__c is not already an external id on Account, make it so. And then use the following code:
If this helps, please mark it as the best answer
Thanks for taking the time to review the code and add on it. I tried to the code you wrote above but I got back this error message:
Error: Compile Error: Illegal assignment from Account to Id at line 11 column 5
Thanks for the quick turnaround. I was finally able to save the code, when I tried to create a test Bodytrace log record, I got this error message:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger AutocreateBTWeightRecordsAndMatchitToAccount caused an unexpected exception, contact your administrator: AutocreateBTWeightRecordsAndMatchitToAccount: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, Field name provided, IMEI__c is not an External ID or indexed field for Account: []: Trigger.AutocreateBTWeightRecordsAndMatchitToAccount: line 16, column 1
How can fix this issue?
Thanks for your help!