+ Start a Discussion

get value of a read-only field

hi all,


i need to capture the details of a read-only field in Apex code. Please suggest some way.




The value is available in APEX, you just can't update it?

hi Harmpie,


i dont want to update the value of read-only field. i need to jus capture the value.

and more-over the field is read-only for a certain profile only.


Is there any way that we can change the profile in run-time. even that can solve the problem.


Thanks in advance,



By default an APEX class runs as system, so you will not have any limitations profile-wise.



but am not able to get the value.

i use a piece of code like

String name= Object_name.Custom_read_only _field;

Oblect_name can be any standard object.


if there is any other way please send it acrosss..

i even set the class to "public without sharing".

I there any other way.


Some more info would help:


1) What error are you receiving trying to use the value?

2) Can you post some actual code?


public without sharing class Generator{

public static void generate(CompanyProfile cmp){

String profileID=cmp.profileID__c;---> read-only field.


this line is not getting any value. i had set this field property as read-only in the layout.


or-else can you help me to get the ID of the parent record when i clone the same. if i can get it ,i can access the SOQL query and get the value.


Sorry, but your story does not make any sense. The line you're talking about should correctly assign the value of profileID__c to String profileId.... read-only or not.


It's more likely that the field actually has NO value.. Did you quey the field in your SOQL when retrieving the passed cmp record?