You need to sign in to do that
Don't have an account?
wilbur07
How do I assign value to a parent-child field?
I have this code which gives an error when I try to compile my trigger:
for (Asset a : Trigger.new) {
if (Trigger.isInsert) {
AssetHistory__c nli0 = new AssetHistory__c();
nli0.Name='Created';
nli0.Asset__r.Id=a.Id;
insert nli0;
}
else {
the error is Error: Compile Error: Field is not writeable: Asset__r.Id at line 8 column 9
I tried this replacement which compiles but does not assign any value to the parent field Asset__r when the trigger executes.
nli0.Asset__r=a;
and these lines all give cannot write errors, or field not in AssetHistory__c object:
nli0.Asset__rId = a.Id;
nli0.AssetId = a.Id;
My question is, how do I assign a parent Asset to my AssetHistory__c objects?
Any help is appreciated.
for (Asset a : Trigger.new) {
if (Trigger.isInsert) {
AssetHistory__c nli0 = new AssetHistory__c();
nli0.Name='Created';
nli0.Asset__r.Id=a.Id;
insert nli0;
}
else {
the error is Error: Compile Error: Field is not writeable: Asset__r.Id at line 8 column 9
I tried this replacement which compiles but does not assign any value to the parent field Asset__r when the trigger executes.
nli0.Asset__r=a;
and these lines all give cannot write errors, or field not in AssetHistory__c object:
nli0.Asset__rId = a.Id;
nli0.AssetId = a.Id;
My question is, how do I assign a parent Asset to my AssetHistory__c objects?
Any help is appreciated.
wilbur07
Asset__r should be Asset__c as in Asset__c=a.id -- works fine now.