Cheat Sheets
Salesforce 1 Developer Cheatsheet Salesforce 1 Admin Cheatsheet App Logic: Process Automation Cheatsheet App Logic: Formulas Cheatsheet App Logic: Apex Code Cheatsheet UI: Lightning Components Cheatsheet UI: Visualforce Cheatsheet Custom […]
Create a map for duplicate contacts by phone or email id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
Map<String,List<Contact>> phoneMap = new Map<String, List<Contact>>(); List<Contact> scope = [SELECT Id,Phone,Email,CreatedDate FROM Contact WHERE (Phone!='' OR Email!='') order by createddate desc]; for(Contact ct:scope) { String phone = String.valueOf(ct.Phone); String email = String.valueOf(ct.Email); if(String.isNotBlank(String.valueOf(ct.Phone))) { phone = phone.replace('-', '').replace('(', '').replace(')', '').replace(' ', '').replace(',', ''); if (phoneMap.containsKey(phone)) { List<contact> c = phoneMap.get(phone); c.add(ct); } else { phoneMap.put(phone, new List<Contact>{ ct }); } } else{ if (emailMap.containsKey(email)) { List<contact> c = emailMap.get(email); c.add(ct); } else { emailMap.put(email, new List<Contact>{ ct }); } } } for(String key:phoneMap.keySet()) { List<Contact> ct = phoneMap.get(key); if(ct.size()>1) { System.debug('phoneMap: ' + key + ': ' + ct.size() + ': ' + phoneMap.get(key)); } } for(String key:emailMap.keySet()) { List<Contact> ct = emailMap.get(key); if(ct.size()>1) { System.debug('emailMap: ' + key + ': ' + ct.size() + ': ' + emailMap.get(key)); } } |
Don’t just create the Model, implement Repository Pattern
Think a scenario where your application uses MySQl database, and you need to switch to a different DB,that means are you going to rewrite your database logic again?. Thanks to […]
Generate dummy data in Laravel using Model Factory
Here are the steps needed to create dummy data Lets create a model called Sample with migration file, using php artisan command
1 |
php artisan make:model Sample -m |
Run the migration by
1 |
php artisan migrate |
Generate a factory […]