• Sha 8
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
i want to insert records through apex batch class in an object having auto number field for one column in the object

i am getting the below error message
First error: Insert failed. First exception on row 0 with id a049000000EoeVXAAZ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

below is my batch apex code:
global class batchapexexample implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT  Account__c,templ__c,Amount__c  FROM Balances__c';
        return Database.getQueryLocator(query);
    }
  
    global void execute(Database.BatchableContext BC, List<balances__c>scope)
    {
      insert scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
       
    }

  • July 14, 2014
  • Like
  • 0
i have two apps when a user is created in one app automatically the same user should be created in another app
  • July 08, 2014
  • Like
  • 0
i want to insert records through apex batch class in an object having auto number field for one column in the object

i am getting the below error message
First error: Insert failed. First exception on row 0 with id a049000000EoeVXAAZ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

below is my batch apex code:
global class batchapexexample implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT  Account__c,templ__c,Amount__c  FROM Balances__c';
        return Database.getQueryLocator(query);
    }
  
    global void execute(Database.BatchableContext BC, List<balances__c>scope)
    {
      insert scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
       
    }

  • July 14, 2014
  • Like
  • 0

Hi,

Can any one help to this scenario.

 

Page Code:-

<apex:page controller="xyzcon" >
<script>
    function addElement(value)
        {
        //alert(value);
            var ni = document.getElementById('myDiv');
            var numi = document.getElementById('theValue');
            var num = (document.getElementById('theValue').value -1)+ 2;
            numi.value = num;
            var newdiv = document.createElement('div');
            var divIdName = 'my'+num+'Div';
            newdiv.setAttribute('id',divIdName);
            newdiv.type='Button';
        
   <!-- If conditions that helps to add a control dynamically based on field types -->
        if(value=='STRING')
        {
            newdiv.innerHTML = 'Name:<input type="+value+" Name="DVF__STRING" />';
        }
        if(value=='EMAIL')
        {
            newdiv.innerHTML = 'Email:<input type="+value+" Name="DVF__EMAIL" />';
        }
        if(value=='PHONE')
        {
            newdiv.innerHTML = 'Phone:<input type="+value+" Name="DVF__PHONE"/>';
        }
        if(value=='PICKLIST')
        {
            newdiv.innerHTML = 'Location:<select type="+value+" Name="DVF__PICKLIST"><option value="Hyderabad">Hyderabad<option value="Banglore">Banglore<option value="Chennai">Chennai';
        }
        if(value=='TEXTAREA')
        {
            newdiv.innerHTML = 'About You:<textarea rows="5" cols="20" Name="DVF__TEXTAREA"/>';
        }
        if(value=='BOOLEAN')
        {
            newdiv.innerHTML = 'CheckBox:<input type="Checkbox" Name="DVF__BOOLEAN"/>';
        }
        if(value=='DATE')
        {
            newdiv.innerHTML = 'Date:<input type="text" Name="DVF__DATE"/>';
        }
         ni.appendChild(newdiv);
     }
     
  <!-- function that helps to get the form elements -->
 
     function getfieldvalues(oForm)
     {  
      str = oForm.name;
        for (i = 0; i < oForm.length; i++)
        {
            str += oForm.elements[i].name+ " -- "+ oForm.elements[i].value + "\n";
        }
        alert(str);
     }

</script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!Data}" var="Fvalues">
                    <apex:column headervalue=" Field Names ">
                        <a href="javascript&colon;;" onclick="addElement('{!Fvalues}')">{!Fvalues}</a>
                    </apex:column>
                </apex:pageBlockTable>
             </apex:pageBlockSection>
        </apex:pageBlock>
        <input type="hidden" value="0" id="theValue" />
    <div id="myDiv"> </div>
    <input type="button" value="Submit" onclick="getfieldvalues(this.form)"/>
   </apex:form>
</apex:page>

 

 

Controller Code:-

public class xyzcon
{
    List<Schema.DisplayType> fieldtypelst= new List<Schema.DisplayType>();

        public List<Schema.DisplayType> getData()
        {
                Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
                Schema.SObjectType systemObjectType = gd.get('E__C') ;
                Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
                Map<String, Schema.SObjectField> M = r.fields.getMap();
                Set<String> fieldNames = M.keySet();               
                    for(String fieldName : fieldNames)
                    {
                            Schema.SObjectField field = M.get(fieldName);                                                    
                            Schema.DescribeFieldResult fieldDesc = field.getDescribe();
                            if(fieldDesc.iscustom())
                            fieldtypelst.add(fieldDesc.getType());  
                    }
               return fieldtypelst;
        }
}

 

 

How can i pass  'str' value from JavaScript method to apex Controller.

 

 

Can u please suggest me.

 

 

Thanks & Regards;

Ramya