function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC DummySFDC Dummy 

How to insert all existing record in another object

Hi all

How to copy all existing record to nother object when record created...uisng trigger
salesforce mesalesforce me
trigger UpdateSpecificProduct on Product__c (after update) {

    List<Id> idProduct = new List<Id>{};

    for(Product__c p: Trigger.new){
        idProduct.add(p.id);
    }


    Specific_Product__c[] prodToUpdate = [select id 
                                            from Specific_Product__c 
                                            where Specific_Product__c.Product_ID__c IN :idProduct];

    {
        Description__c = p.Description__c,
        Availability__c = p.Availability__c,
    }

    update prodToUpdate;

}
 
trigger UpdateSpecificProduct on Product__c (after update) {

List<Id> idProduct = new List<Id>{};
Map<Id, Product__c> productDetails = new Map<Id,Product__c>();

for(Product__c p: Trigger.new){
    idProduct.add(p.id);
    productDetails.put(p.id,p);}


Specific_Product__c[] prodToUpdate = [select id,description__c, availability__c, Product_ID__c from Specific_Product__c where Specific_Product__c.Product_ID__c IN :idProduct];
for(Specific_Product__c specific : prodToUpdate){

    specific.Description__c = productDetails.get(specific.product_id__c).Description__c;
    specific.availability__c = productDetails.get(specific.product_id__c).availability__c

}

update prodToUpdate;

}
Himanshu ParasharHimanshu Parashar
Hi,

You can use Process builder to create new records.

1. Selet Object
2. Select Criteria
3. Select Create a record from the list in Action.

User-added image


Thanks,
Himanshu