You need to sign in to do that
Don't have an account?
How to use Custom Field in Apex Code.
Hi All,
I have created Custom Field in Contact Object (Name: RegistrationAccount), but when I try to access it my Apex code its giving an error.
Code:
Contact c = new Contact(
AccountId=a.Id,
FirstName = firstName,
LastName = lastName,
Account = a,
Department = department,
RegistrationAccount='UVA', // My Custom Field
Email = email,
Phone=phone,
Title = title,
MailingStreet = streetAddress,
MailingCity = cityAddress,
MailingState = stateAddress,
MailingPostalCode = postalCodeAddress,
MailingCountry = countryAddress);
insert c;
Error: Compile Error: Invalid field RegistrationAccount for SObject Contact at line 45 column 33
Custom Field API Name :Registration Account_c
Hi,
For custom field you have to append "__c" at the last. means you have to take API Name of custom field.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
Thanks for Replying...
I have used API name still it is not working...Is there any relationship or mapping require. Thanks in advance.
No need for any relationship or mapping require here. what is the datatype of RegistrationAccount__c of this field?
If you are using the correct API name and the field is not visible then it will gives you the same error.
Hope it helps.
As per your original error you are getting compile error which means you get error while you save code.
Reason API name is wrong
Fix - Use correct API name after checking in object defination
If you are getting run time error tell me exact error message and type of field?