Thursday, September 6, 2018

How to insert records of two different objects to the database using one single dml statement in salesforce??

This is the question that is usually asked in companies during interview that how can you  insert records of two different objects using one single dml statement. so after reading this article you will be able to explain your interviewer that how to do this.


  1.  First you need to create the instance of each object whether you are working with salesforce standard objects or custom objects. for example
          Account acc1 = new Account(Name = 'anyName');
          Contact con1 = new Contact(LastName = 'anyLastName');
         
       2.  Then you need to create the list of sObject to insert those instances created above into it.

          List<sObject> sObjectList = new List<sObject>();
  
       3.  Now you have to add those instances of different objects to the sObject List

          sObjectList.add(acc1);
          sObjectList.add(con1);
      
        4.  Now simply write one insert dml statement for sObjectList to insert both objects records                     simultaneously to the database.
     
            insert sobjectList;

hope you get useful information by reading the article.

Thanks.



Tuesday, September 4, 2018

How to enable user to enter only integer values to the input box using jQuery.


Answer:

Put this code in script tags and you'll be only able to enter only integer values in the input box.

$(document).ready(function(){
    $("input").keyup(function(){
      $(this).val( $(this).val().replace(/[^0-9]+/, '') );
        if($(this).val() == ''){
          $(this).val(0);                                 
        } 
    });
});