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
ForceRookieForceRookie 

How to set the Name using Apex Aura Controller?

Help me on how to set the Name based on selected Object (from dropdown) on upsert.

I'm using Custom Settings.

@AuraEnabled
    public static void saveCustomSettings(MyCustomSettings__c cs){
        MyCustomSettings__c cust = new MyCustomSettings__c();
        cust = cs;
        upsert cust;
    }

User-added image
Best Answer chosen by ForceRookie
ForceRookieForceRookie

No thanks, guys. I've already got the answer. I updated it to this:

if (cust.Objects__c != null) {
            cust.Name = cust.Objects__c;
            upsert cust;
        }

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi ForceRookie,
Greetings to you!

- I implemented in my Org. Please use the below code[Solved]  : -
@AuraEnabled
    public static void saveCustomSettings(MyCustomSettings__c cs){
        MyCustomSettings__c cust = new MyCustomSettings__c();
        cust.Name = cs.Name;
        upsert cust;
    }
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Ajay K DubediAjay K Dubedi
Hi ForceRookie,
Try below code it may helpful for you
@AuraEnabled
    public static void saveCustomSettings(MyCustomSettings__c cs){
        MyCustomSettings__c cust = new MyCustomSettings__c.getInstance(cs);
  cust.Size__c = 908;
  cust.Name = 'New Name';
  update cust;
    }

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
ForceRookieForceRookie

No thanks, guys. I've already got the answer. I updated it to this:

if (cust.Objects__c != null) {
            cust.Name = cust.Objects__c;
            upsert cust;
        }
This was selected as the best answer