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
force shahidforce shahid 

How to check how many records inserted & how many records updated after importing csv file using data import wizard

Hi friends , 

I write a trigger for importing records in custom object. while importing records in custom object , i written some condition for importing these record into contacts and Leads objects at the same time. 
How do you know the how many records inserted in contacts , how many updated in contacts object. Same issue for lead object also . In my org i  have already records. and I import more than 1000 records . That's y i need to find out this one .
Is it possible ?
Diksha Goel 6Diksha Goel 6

Hey Shahid,
Before you introduce a large number of records to your database, I recommend you do a small test import to make sure that your data is importing correctly. In putting together a set of sample data, try to do the following:
Send data to each field. Each specific record doesn’t necessarily need to have data for every field (although that’s a bonus because it makes it easier to test your data submission), but you should be sending data to each field in your CSV so you can make sure it’s all mapping over correctly.
Make sure the data is varied. Don’t send records that have the same values for the majority of fields. You’re trying to make sure you don’t have any errors in your data, and you probably won’t find any if you’re only testing a few values.

And refer the below link and follow the steps,This will tell you how many records were created.

https://help.salesforce.com/articleView?id=000187883&type=1


Regards,

Diksha Goel

http://www.zen4orce.com

force shahidforce shahid
Hi Diksha , 
Good Morning . Thanks for your information. I go through this link . It gives the information of the importing file status of custom object. But my requirement is status of contact and lead  object . how many records inserted in Contact & lead like that.  I got this information from logs file after importing the csv file.

In logs only i checkthe debug only option . in this Option i got a information . But i don't know how to send this report to system admin . Plz help me  to solve this issue

Thanks in Advance.

Regards,
Shahid.
Sukanya BanekarSukanya Banekar
Hi Shahid,

You can achieve this functionality by writting trigger. 
Also you need to create List custom setting to store count of imported data.
Create custom setting for e.g Count__c. Now create 2 number fields for Contact object e.g.Count Insert Contact and Count Update Contact. So you can keep count of recently imported contacts in custom setting. Also Follow the same for lead
trigger countContact on Contact (after Insert, after update) {
    if(trigger.isAfter){
    list<Count__c> cntCustomSetting = [SELECT Name from Count__c where Name = 'Contact Count' limit 1];
        if(trigger.isInsert){
           Integer count = trigger.new.size();
           if(cntCustomSetting.size() ==1 ){
               cntCustomSetting[0].Count_Insert_Contact__c = count;
               update cntCustomSetting ;
               
           }
           else{
               Count__c cnt = new Count__c();
               cnt.Name = 'Contact Count';
               cnt.Count_Insert_Contact__c = count;
               insert cnt;
           }
           
        }
        else if(trigger.isUpdate){
            Integer countUpdate = trigger.new.size();
            if(cntCustomSetting.size() ==1 ){
               cntCustomSetting[0].Count_Update_Contact__c = countUpdate ;
               update cntCustomSetting ;
               
           }
           else{
               Count__c cnt = new Count__c();
               cnt.Name = 'Contact Count';
               cnt.Count_Update_Contact__c = countUpdate ;
               insert cnt;
           }
        }
    }
}

You can write different class and format the code. 
Let me know if this helps you to solve your problem.

Thanks,
Sukanya Banekar
 
Mustafa JhabuawalaMustafa Jhabuawala
Hi Shahid,

You just need to add few lines in your trigger, to get the inserted and updated record count.

If you can share your trigger code, then it will be easier to identify where to add the code to get the count.

You will get count by two ways -
1. You can maintain a flag in for loop where you might be adding records in a list which has to be inserted once the loop ends and same for update.
2. And if you are using any collections like list/set/map to insert or update then in that case you can also get the count through collection itself if you have seperate variables for insert and update. 

If you want to maintain the count per transaction then above solution will work fine. But if you want to maintain the count regardless of the transactions then in that case you can use custom setting to store the counts as Sukanya suggested in above mentioned solution.

Hope this helped you.

Thanks,
Mustafa Jhabuawala
Technical Lead at Zen4orce (http://www.zen4orce.com)