You need to sign in to do that
Don't have an account?
Jason Kuzmak 12
Why am I able to save a class that references non-existent field "customObject.Notes"?
This is a screenshot of a saved apex class.
The bare bones essentials:
public without sharing class WebOrderMethods { public static Map<String,String> webOrderMap = new Map<String,String>(); public static List<Map<String,String>> lineItemListMap = new List<Map<String,String>>(); public static Web_Order__c buildWebOrder() { Web_Order__c thisOrder = new Web_Order__c(); if(webOrderMap.size() > 0){ for(String key : webOrderMap.keySet()){ String value = webOrderMap.get(key); if(key == null || value == null){ continue; } switch on key { when 'Email' { thisOrder.Contact_Email__c = value; } when 'Notes' { if(thisOrder.Notes == null){ thisOrder.Notes__c = value; } else{ thisOrder.Notes__c += '\r\n'+value; } } when 'ShipmentMethod' { thisOrder.Shipment_Method__c = value; } } } } return thisOrder; } }
I found an issue with my code in which I was referencing a custom field improperly. Here I'm iterating through a list of my custom object records "Web_Order__c", and I noticed I forgot to include the "__c" affix.
Just to test, I tried to query this field thru Anon Apex and got the expected error:
Why did this save properly if there's no such field?
The resaon it saved is because you can have notes related list on the object so the code is reffering to that when saving. If you give some other variable it will not allow to save it.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
The resaon it saved is because you can have notes related list on the object so the code is reffering to that when saving. If you give some other variable it will not allow to save it.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Ok thanks! That makes perfect sense; feels obvious in hindsight!