Closed martingaleh closed 1 year ago
Sorry to hear you're having difficulties getting this to work.
I hope this clarifies things a little:
sfab_FabricatedSObject fc = new sfab_FabricatedSObject( Contact.class ).set( 'Name', 'The Contact' );
sfab_FabricatedSObject fap = new sfab_FabricatedSObject( Account.class ).set( 'Name', 'The Account' );
// Setting a parent requires you to set the relationship, not the Id
fc.set( 'Account', fap );
// or
fc.setParent( 'Account', fap );
// Setting a child requires you to 'add' them one by one
fap.add( 'Contacts', fc );
// or
fap.addChild( 'Contacts', fc );
// Or you can set them in a list
fap.set( 'Contacts', new List<sfab_FabricatedSObject>{ fc } );
// or
fap.setChildren( 'Contacts', new List<sfab_FabricatedSObject>{ fc } );
Also improved the docs to explicitly provide an example of setting the parent using another fabricated SObject.
Examples already existed of adding children in this way, so not changes to docs to cover this.
I think its the trickiness of the salesforce documentation. The field api name for this standard object is accountid, but the field name is account. If you just did new contact(accountid = new account()), I think it works, so that's what iv'e been doing all my life and figured it would similarly work here. Thanks for being so responsive. this library is so much easier to use than others...
No worries, glad I could help, and that the library is useful!
On Sat, 3 Dec 2022, 19:06 martingaleh, @.***> wrote:
Closed #25 https://github.com/mattaddy/SObjectFabricator/issues/25 as completed.
— Reply to this email directly, view it on GitHub https://github.com/mattaddy/SObjectFabricator/issues/25#event-7946789021, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRYYB2MIXD4PU67EXKQ6V3WLOK25ANCNFSM6AAAAAASSNSQZE . You are receiving this because you commented.Message ID: @.***>
sfab_FabricatedSObject fc = new sfab_FabricatedSObject(Contact.class... sfab_FabricatedSObject fap = new sfab_FabricatedSObject(Account.class... fc.set('AccountId',fap) //doeesnt' work fap.set('Contacts',fc) //doesn't work fap.addChild('contacts',fc) works fc.setParent('AccountId',fap) //doesnt' work fc.addChild('AccountId',fap) //doesnt' work. Shouldn't have, but just in case.