+ Start a Discussion

Custom Setting Data Insert by Apex DML Operation



  Any one confirm Custom Setting Data can be insert by Apex DML Operation ?

  Because i am getting the below Error during Insert.( Using Apex Batch I am inserting ).


System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, An unexpected error occurred. Please include this ErrorId if you contact support: 1512696965-168 (489760386): []

Thanks and Regards

Thangaraj S





Are you trying to add a custom setting by inserting? I'm quite sure that's not possible because that information is more than likely stored as metadata. Could you post some code please.





You should be able to insert custom settings data like you would with any custom object - you just need to make sure when you're inserting the record that the Name is unique.  It may help if you post your code to see if we can see anything wrong with it.


The simplest explanation is that Apex was tired at 12:18AM


Actually, I too would like to see the code.  What kind of custom setting are you inserting?  A hierarchy or a list?


Tired?... Apex never sleeps.


It "seems" like you are trying to insert List type CS records with names that are greater than SFDC is expecting.  Can you try inserting CS records where the name field is less than 20 single byte characters?





  Our Task is Get the Custom Object Data and Insert in to Cutom Setting using Batch Apex


global class BatchUpdateUser implements Database.Batchable<SObject>, Database.Stateful {

    String query;

    public String message { get; set; }

    global Database.QueryLocator start(Database.BatchableContext bc) {

        return Database.getQueryLocator(query);


global void execute(Database.BatchableContext bc, SObject[] shainBatch) {

        List<UserList__c> userList = new List<UserList__c>();

        for (Integer i=0; i<shainBatch.size(); i++) {

            Shain__c shain = (Shain__c)shainBatch[i];

            UserList__c user = new UserList__c();

            user.Name = shain.Name;

            user.ShainNo__c = shain.ShainNo__c;

            user.Password__c = '12345';

            user.Shain_Groupe__c = shain.Shain_Groupe__c;

            user.mail__c = shain.mail__c;

            user.Shain_Division__c = shain.Shain_Division__c;

            user.ON_OFF__c = shain.ON_OFF__c;




        upsert userList;

        System.debug('Insert Completed');


 global void finish(Database.BatchableContext bc) {

         System.debug('Finish Started');

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        mail.setToAddresses(new String[]{'kbarusara@yahoo.com'});


        mail.setSenderDisplayName('Batch Process - Update User Over.');

        mail.setSubject('Update User Complete');

        mail.setPlainTextBody('Batch Processing - Update User has Completed.');

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

        System.debug('Finish End');


    public PageReference updateUser() {

        try {

            query='Select id, Name, Password__c, ShainNo__c, Shain_Groupe__c, mail__c, Shain_Division__c, ON_OFF__c from Shain__c order by ShainNo__c asc';

            ID batchprocessid = Database.executeBatch(this);

            System.debug('Batch Over');

            message = 'Update User Batch run has Completed.';

        } catch(Exception ex) {


            System.debug('Exception Occured');

            message = 'Update User Batch run Failed.';


         System.debug('Return Over');

        return new PageReference('/apex/BatchUpdateUser');




Finaly Find the Problem if we insert Name as Kanji character with more then 5 double byte char then problem


Sample Data Name-->関根 秀治

The Below data are working correctly



Thanga 関根

関根 thanga



Even Custom Setting Manage Screen we insert the same above 5 double byte example name it gives error.


Upto 4 Double Bytes char its working , if we add 5th Double bytes then gives problem.



Name is Unique we deleted all the record and insert again that time also error.

The Above Kanji Having total 10 Byts only (Space Double byte ).

Using Apex DML operation without Batch insert Single byte char its working fine.






I didn't see anything wrong with the code.  I just tried entering 5 japanese characters using the UI too.  It failed too.  I'm sure it has nothing to do with batch.