+ Start a Discussion
mittal_sfdcmittal_sfdc 

How can I delete a custom field which is also a required field ?

I have a custom field which I need to delete and it is also a required field which is used in apex class and visualforce page. I dnt need that feld anymore.. is there a way I  can delete a field or make that field which is not a required field. 

Bhawani SharmaBhawani Sharma
You can simply mark it not-required from field edit screen. but if you want to delete this, first you will have to remove all the references and then you would be able to delete. Make sure, all data stored in this field will be lost.
Rahul_sgRahul_sg

when you hit the delete button it will show you the referenced i.e. VF pages and apex class where this field has been used.

 

Just go to those components and EDIT them : You can comment the field in your code or simply delete it from the code and save the components.

 

Now you are ready to delete this field. 

Prakash@SFDCPrakash@SFDC

If the field is referenced in many componentsthen  take all those components into eclipse and dereference in one stretch after that delete that field.

kevindotcarkevindotcar
WARNING:   This is not recommended, and will certainly make the Spirits of programming weep for you;   But If you do something like this;
 
sObject sObj = Schema.getGlobalDescribe().get('Account').newSObject() ;
    if(sObj.getSobjectType().getDescribe().fields.getMap().containsKey('myBooleanField')) {
          sObj.put('myBooleanField' , true) ;
          }
 
....Deleting or renaming "myBooleanField" won't be picked up.