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
ThylaksoftThylaksoft 

Why LastActivityDate field is not writeable

In my case, i need to create trigger for insert LastActivityDate for custom object while update the lead.

 

when i try the above task salesforce system shows the error:

 

Field is not writeable: MarketingObject__c.LastActivityDate

 

my trigger:

 

 

trigger AddMarketObjectFields on Lead (after Update) { List<MarketingObject__c> MarketingObjectVar = new List<MarketingObject__c>(); for(Lead lead:System.Trigger.new) { if(lead.Status == 'Closed - Converted') { // Assign the Activity date from lead object to Marketing object MarketingObjectVar.add(new MarketingObject__c(Name = lead.Name,LastActivityDate = lead.LastActivityDate)); insert MarketingObjectVar; } } }

 

anybody have a solution or valuable suggestion for this query would be greatly appreciated  !


 

jkucerajkucera
Create a custom field instead of using the system LastActivityDate, so you can update the field as needed.  You could use a workflow rule to copy the system field if desired, or simply manually copy it in your trigger.
ThylaksoftThylaksoft
Thank you very much for your response John Kucera,i do try for your idea and get back to you.