If I have a page (in my case, MeUsRole), that has a reference relationship to another (ContentSearch), and I I have a BelongsTo field set up to select the related content search…but I’d like to have an add button beside the BelongsTo field to create a new Content Search as a convenience to the user…how should this be done?
Apex Add Button wants an array, which doesn’t exist here…
so a Button with method, and just create a new ContentSearch, save it in the id field (for the references relationship of the MeUsRole) and then router to the detail page for the new Content Search?
am guessing this is correct?
const newContentSearch = await ContentSearchFormGroup.create({ name: this.meUsRole.name, type: 'Blog' }, {});
debug('newContentSearch', newContentSearch);
this.router.navigateByUrl('/admin/contentSearches/' + newContentSearch.id);
Yes, that’s correct but you don’t have to use ContentSearchFormGroup.create(). You could use ContentSearch.create() instead. Either way you’ll get a new ContentSearch object that can be referenced in the router.navigateByUrl call.
1 Like