Copy records between two similar object

Copy records between two similar object 


Suppose from object A to object B (with same fields)


List<objectA__c> oAList = [Select Id, Name, fieldA__c, fieldB__c from objectA__c];

List<objectB__c> oBList = new List<objectB__c>();

for(objectA__c oA : oAList){

objectB__c oB = new objectB__c();

oB.Name = oA.Name

oB.fieldA__c =  oA.fieldA__c;

oB.fieldB__c = oA.fieldB__c;

oBList.add(oB);

insert oBList;

Comments