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
ChiyaChiya 

Need to insert 500 Contact records for a Account record and 1 to 1 mapping should be there between them. Help me to write the code for this..

Shubham Jain 338Shubham Jain 338
Hi Chiya,

If we are inserting 500 contacts for an Account then there is 1 to many relationship.
Can you please explain it more?

Thanks
Shubham Jain
Harshit Kumar 27Harshit Kumar 27
Hi Chiya,

Code to insert 500 contact records =>

public class ContactProcessor {
    public static void insertContact(){
        List<Contact> conList = new List<Contact>();
        Contact con;
        for(Integer i = 0; i < 500; i++){
            con = new Contact();
            con.LastName = 'Test ' +i;
            conList.add(con);
        }
        if(conList.size()>0) insert conList;
    }
}

// Run this class in execute anonymous window (Ctrl+E). 
ContactProcessor.insertContact();

As mentioned by Shubham, if we are inserting 500 contacts for an Account then there is 1:N relationship.

Thanks
Harshit Kumar
transe divain 10transe divain 10
CVS is one of the largest drugstore chains in the United States that provides high-quality healthcare and wellness solutions. cvssurvey (https://takesurvey.onl/www-cvssurvey-com/" target="_blank)
Libra AnaLibra Ana
This post of insert 500 Contact records for an Account record and 1 to 1 mapping should be there between them, is so helpful as well for the new ones but there are also very intellectual and desiring in giving best dissertation writing help (https://londondissertations.co.uk/) from them in all the way to London city reflectively.