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
amar joshiamar joshi 

Create audit field is enable though i m not able populate the data in Audit field

 

Hi all
i m doing the exercises to populate the data form one salesforce package to another salesforce package 
both packages have same object and same fields now i want to Query data from old package and put in to new package's objects 
i m doing this exercises through apex and create audit field permission is enable and then also i m getting error 
"Field LastModifieddate is not editable"
bellow is the code for reference
List<OLDPKG__Customobj__c> lst = new List<OLDPKG__Customobj__c>();
List<NEWPKG__Custonobj__C> Newlst = new List<NEWPKG__Custonobj__C>();
lst =  [select all fields from OLDPKG__Customobj__c];
for(OLDPKG__Customobj__c  ab : lst )
{
NEWPKG__Custonobj__C  atta = new NEWPKG__Custonobj__C();
atta.put('LastModifiedDate',a.LastModifiedDate);
atta.put('LastModifiedById',a.LastModifiedById);
atta.put('IsPrivate',a.IsPrivate);
atta.put('IsDeleted',a.IsDeleted);
atta.put('Description',a.Description);
atta.put('CreatedDate',a.CreatedDate);
atta.put('CreatedById',a.CreatedById);
Newlst.add(atta);
}
if(Newlst.size() > 0)
{
insert Newlst;
}

Hi all


i m doing the exercises to populate the data form one salesforce package to another salesforce package 
both packages have same object and same fields now i want to Query data from old package and put in to new package's objects 

 

i m doing this exercises through apex and create audit field permission is enable and then also i m getting error "Field LastModifieddate is not editable"

 

bellow is the code for reference

 

 

List<OLDPKG__Customobj__c> lst = new List<OLDPKG__Customobj__c>();

 

List<NEWPKG__Custonobj__C> Newlst = new List<NEWPKG__Custonobj__C>();

 

lst =  [select all fields from OLDPKG__Customobj__c];

for(OLDPKG__Customobj__c  ab : lst )

{

  NEWPKG__Custonobj__C  atta = new NEWPKG__Custonobj__C();   atta.put('LastModifiedDate',a.LastModifiedDate);

  atta.put('LastModifiedById',a.LastModifiedById);

  atta.put('IsPrivate',a.IsPrivate);

  atta.put('IsDeleted',a.IsDeleted);

  atta.put('Description',a.Description);

  atta.put('CreatedDate',a.CreatedDate);

  atta.put('CreatedById',a.CreatedById);

  Newlst.add(atta);
}

if(Newlst.size() > 0)

{

  insert Newlst;

}



 

_Prasu__Prasu_

Hello Amar,

 

Exception is due to some standard fields like LastModifiedDate, LastModifiedById, CreatedDate , CreatedById are in uneditable by default.

Salesforce may avail it on request.

 

Thanks,

amar joshiamar joshi

Hi,

 

Because of that i have enable the create Audit field feature and intersting thing is that if i m inserting data through Data lodar it allows me to insert the data in LastModifiedDate, LastModifiedById, CreatedDa​te , CreatedById fields bt through apex its not respecting the ceate audit field features

 

Experts, want  some help on this ??how do i accomplish this in apex..??

 

Waiting for ur response..

_Prasu__Prasu_

Salesforce does provides some key to partners which allows such thing from the API.