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
Deepak Sharma 46Deepak Sharma 46 

Field is not writable :: actNew.ShippingAddress

Hi All,
Please help in resolving the field not writable issue being thrown in below code . The object and filed level sharing is being set appropriately

trigger AccountAddressTrigger on Account (before insert , before update) {
    System.debug('Welcome to the Triggers World');
    List<Account> lstAccount=new List<Account>();
    For (Account actNew :Trigger.New)
    {
    if(actNew.BillingAddress !=NULL && actNew.Match_Billing_Address__c==true)
    {
        actNew.ShippingAddress=actNew.BillingAddress;
    }
        lstAccount.add(actNew);
    }
    
    insert lstAccount;
    
}
Yogesh KulkarniYogesh Kulkarni
Check the actual API names for different fields in documentation. Usually the fields are like ShippingStreet, ShippingCity etc. Check following URL
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_account.htm
https://help.salesforce.com/apex/HTViewHelpDoc?id=account_fields.htm&language=en
KapilCKapilC
Hi Deepak,

There are some special fields in salesforce which constructs with other fields like address in your case. BillingAddress and shipping address get constructed with other fields like city, postalcode country etc. So you have to update these fields seprately.
Apart from that you are writing trigger so you can not insert or update the records which are part of the triggger.new records. Please find the below code hope this will help you to solve your problem.
trigger AccountAddressTrigger on Account (before insert , before update) {
    System.debug('Welcome to the Triggers World');
    
	for (Account actNew :Trigger.New){
		if(actNew.BillingAddress != null && actNew.Match_Billing_Address__c == true){
			actNew.ShippingAddress = actNew.BillingAddress;
			actNew.ShippingCity = actNew.BillingCity; 
			actNew.ShippingCountry = actNew.BillingCountry;
			actNew.ShippingPostalCode = actNew.BillingPostalCode;
			actNew.ShippingState = actNew.BillingState;
			actNew.ShippingStreet = actNew.BillingStreet;
		}
  
	}
}
Thanks,
Kapil
(forcecube@gmail.com)
 
Imane ABDOUImane ABDOU
Thank you Kapil, it works !
Valteir JuniorValteir Junior
Thanks Kapil. You save my life !! 
Navaneeth SankarNavaneeth Sankar
Hi, Kapil 
mine is still showing error
trigger billingAddress on Account (after insert) {
    for(Account a : Trigger.new){
       a.ShippingAddress = a.BillingAddress;
       a.ShippingCity = a.BillingCity;
       a.ShippingCountry = a.BillingCountry;
       a.ShippingPostalCode = a.BillingPostalCode;
       a.ShippingState = a.BillingState;
       a.ShippingStreet = a.BillingStreet;
    }

}
Ngô Hoàng DươngNgô Hoàng Dương
Hi, Navaneeth
you can direct to https://dfc-org-production.force.com/forums/ForumsMain?id=906F0000000kFBpIAM  for answers.
Hope this helps!