salesforcesalesforce-lightningsalesforce-service-cloud

Removing the extra values of Picklist in salesforce DB


How to the remove the extra values of Picklist(which already exists in DB) in salesforce DB? Perhaps, something I want to achieve below like this: Remarried change to Married Divorced change to Single Engaged changed to Single Separated change to Married

Specific question: Can we update values without SOCL query? What are the ways to do this?

PS: Apologies for the basic question, as I'm naive in salesforce.

Any inputs in this regard is highly appreciated!

Thanks!


Solution

  • I could get the SOQL query. Updating here for benefit of others

        //Remarried change to Married
    //Divorced change to Single
    //Engaged changed to Single
    //Separated change to Married
    //Query for single record
    
    //Updating multiple Records:
    //Retrieve list of contacts, whose Marital_Status__c is Remarried, Divorced, Engaged, Separated
    List<Contact> martialType = [Single];
    
    //Loop through those contacts and set Marital_Status__c accordingly
    for (Contact contUpdateObj: martialType) {
    
        //SET operation for Remarried to Married
        if(contUpdateObj.Marital_Status__c == 'Remarried') {
            contUpdateObj.Marital_Status__c = 'Married';
            //System.debug('FirstName= ' + contUpdateObj.FirstName);
            //System.debug('Updated values are = ' + contUpdateObj.Marital_Status__c);
        }
        //SET operation for Divorced to Single
        if(contUpdateObj.Marital_Status__c == 'Divorced') {
            contUpdateObj.Marital_Status__c = 'Single';
            //Printing logs on console
            //System.debug('FirstName= ' + contUpdateObj.FirstName);
            //System.debug('Updated values are = ' + contUpdateObj.Marital_Status__c);
        }
        //SET operation for Enaged to Single
        if(contUpdateObj.Marital_Status__c == 'Engaged') {
            contUpdateObj.Marital_Status__c = 'Single';
             //Printing logs on console
            System.debug('FirstName= ' + contUpdateObj.FirstName);
            System.debug('Updated values are = ' + contUpdateObj.Marital_Status__c);
        }
         //SET operation for Separated to Married
        if(contUpdateObj.Marital_Status__c == 'Separated') {
            contUpdateObj.Marital_Status__c = 'Married';
            System.debug('FirstName= ' + contUpdateObj.FirstName);
            System.debug('Updated values are = ' + contUpdateObj.Marital_Status__c);
        }
    }
    
    //Run a DML update statement, now all account records in the list will have type updated accordingly
    //Remarried change to Married
    //Divorced change to Single
    //Engaged changed to Single
    //Separated change to Married
    //Query for single record
    update martialType;