function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
k practicek practice 

How to avoid readonly fields in below code?

Hi,
         for(Schema.SObjectField objField : Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().values())
                     {
                       if(objField.getDescribe().getName().endsWith('__pc'))
                       {
                           String str=objField.getDescribe().getName();
                           String personaccountFields=str.replaceAll('__pc', '__c');
                           Ocontact.put(str, personaccountFields.get(str));
                       }
                     }

here i was getting readonly fields error .how to solve this error?
                
BalajiRanganathanBalajiRanganathan
You have to use DescribeFieldResult class isCreatable() method
 
DescribeFieldResult fr = objField.getDescribe();

if (fr.isCreatable()) {
  //your code
}

 
k practicek practice
Hi,
Here i was getting Contact object Custom fields.If suppose one custom field is not there in below comparing object(Person object).How to avoid this custom fields and same fields how to update?
  for (Schema.SObjectField objField: Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap().values()) {
                DescribeFieldResult fr = objField.getDescribe();
                if (fr.isUpdateable()) //isCreateable())
                {
                    if (fr.getName().endsWith('__c')) {
                        String str = fr.getName();
                        String contactcustomFields = str.replaceAll('__c', '__pc');
                        System.debug(contactcustomFields);
                        pAccount.put(contactcustomFields, Ocontact.get(str));
                        //update pAccount;
                        System.debug(pAccount.put(contactcustomFields, Ocontact.get(str)));
                    }
                
                }
            }

Help me.....