// Mapping of email addresses to City, Country, and TimeZoneSidKey
Map<String, Map<String, String>> emailToLocationMap = new Map<String, Map<String, String>>{
'DomingoJr.Venci@aei.com' => {'City' => 'Cavite', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Charisse.Fabian@aei.com' => {'City' => 'Cavite', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Rexcee.Toledo@aei.com' => {'City' => 'Laguna', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Chelseia.Aguilon@aei.com' => {'City' => 'Laguna', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Allan.Resus@aei.com' => {'City' => 'Cavite', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Jessica.Song@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Chris.Tian@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Hazel.Wu@aei.com' => {'City' => 'Zhongshan', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Roldan.Ronquillo@aei.com' => {'City' => 'Laguna', 'Country' => 'Philippines', 'TimeZone' => 'Asia/Manila'},
'Daniel.Dearden@aei.com' => {'City' => 'Littlehampton', 'Country' => 'England', 'TimeZone' => 'Europe/Berlin'},
'James.Brind@aei.com' => {'City' => 'Littlehampton', 'Country' => 'England', 'TimeZone' => 'Europe/Berlin'},
'Kelly.Chiah@aei.com' => {'City' => 'Penang', 'Country' => 'Malaysia', 'TimeZone' => 'Asia/Kuala_Lumpur'},
'Sally.Chng@aei.com' => {'City' => 'Penang', 'Country' => 'Malaysia', 'TimeZone' => 'Asia/Kuala_Lumpur'},
'Shiny.Deng@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Patrick.Yu@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Tom.Yang@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Vivi.Li@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Donald.Hoffman@aei.com' => {'City' => 'Fort Collins', 'Country' => 'USA', 'TimeZone' => 'America/New_York'},
'Marcela.Hirales@aei.com' => {'City' => 'Mexicali', 'Country' => 'Mexico', 'TimeZone' => 'America/Mexico_City'},
'Francisco.Zarate@aei.com' => {'City' => 'Mexicali', 'Country' => 'Mexico', 'TimeZone' => 'America/Mexico_City'},
'Jason.Nie@aei.com' => {'City' => 'Zhongshan', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Allen.He@aei.com' => {'City' => 'Zhongshan', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Angel.Wang@aei.com' => {'City' => 'Zhongshan', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Cliff.Zhang@aei.com' => {'City' => 'Shenzhen', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'},
'Declan.Porter@aei.com' => {'City' => 'Hongkong', 'Country' => 'China', 'TimeZone' => 'Asia/Hong_Kong'}
};
// Fetch contacts created **today**
List<Contact> recentContacts = [SELECT Id, FirstName, LastName, Email, AccountId
FROM Contact
WHERE CreatedDate = TODAY
AND AccountId = '001VV00000MYNn8YAH'];
// Get Contact IDs
Set<Id> contactIds = new Set<Id>();
for (Contact con : recentContacts) {
contactIds.add(con.Id);
}
// Fetch existing Partner Users in one query
Set<Id> existingPartnerUserContacts = new Set<Id>();
if (!contactIds.isEmpty()) {
for (User existingUser : [SELECT ContactId FROM User WHERE ContactId IN :contactIds]) {
existingPartnerUserContacts.add(existingUser.ContactId);
}
}
// Fetch all existing usernames in one query
Set<String> existingUsernames = new Set<String>();
for (User u : [SELECT Username FROM User]) {
existingUsernames.add(u.Username);
}
// Fetch the Role ID for 'Supplier Group Account Partner User'
Id partnerRoleId;
try {
partnerRoleId = [SELECT Id FROM UserRole WHERE Name = 'Supplier Group Account Partner User' LIMIT 1].Id;
} catch (Exception e) {
System.debug('⚠️ Role "Supplier Group Account Partner User" not found. Please check the name.');
}
// Get correct Profile ID
Id partnerProfileId;
try {
partnerProfileId = [SELECT Id FROM Profile WHERE Name = 'Partner Community User' LIMIT 1].Id;
} catch (Exception e) {
System.debug('⚠️ Profile "Partner Community User" not found. Please check the name.');
}
// Prepare list of users to insert
List<User> usersToInsert = new List<User>();
List<String> duplicateUsernames = new List<String>();
for (Contact con : recentContacts) {
if (con.Email != null && !existingPartnerUserContacts.contains(con.Id)) {
String generatedUsername = con.Email + '.scar';
// ✅ Skip duplicates and insert only unique usernames
if (existingUsernames.contains(generatedUsername)) {
duplicateUsernames.add(generatedUsername);
System.debug('⚠️ Duplicate Username Found: ' + generatedUsername);
continue; // Skip this user and move to the next one
}
// Get location data based on email
Map<String, String> locationData = emailToLocationMap.containsKey(con.Email) ? emailToLocationMap.get(con.Email) : null;
User newUser = new User(
FirstName = 'SCAR '+con.FirstName,
LastName = con.LastName,
Username = generatedUsername,
Email = con.Email,
Alias = con.LastName.length() > 5 ? con.LastName.substring(0, 5) : con.LastName,
ProfileId = partnerProfileId,
UserRoleId = partnerRoleId,
TimeZoneSidKey = locationData != null ? locationData.get('TimeZone') : 'Asia/Hong_Kong',
LocaleSidKey = 'en_US',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
IsActive = true,
ContactId = con.Id,
Department = 'Supplier',
FederationIdentifier = con.Email,
Country = locationData != null ? locationData.get('Country') : 'China',
City = locationData != null ? locationData.get('City') : 'Unknown'
);
usersToInsert.add(newUser);
existingUsernames.add(generatedUsername); // ✅ Add username to Set immediately
}
}
// ✅ Insert all unique users and handle errors
if (!usersToInsert.isEmpty()) {
try {
insert usersToInsert;
} catch (DmlException e) {
System.debug('❌ Error inserting users: ' + e.getMessage());
}
}
Ly8gTWFwcGluZyBvZ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vdW50cnknID0+ICdNZXhpY28nLCAnVGltZVpvbmUnID0+ICdBbWVyaWNhL01leGljb19DaXR5J30sCiAgICAnSmFzb24uTmllQGFlaS5jb20nID0+ICAgICAgICAgICAgIHsnQ2l0eScgPT4gJ1pob25nc2hhbicsICdDb3VudHJ5JyA9PiAnQ2hpbmEnLCAnVGltZVpvbmUnID0+ICdBc2lhL0hvbmdfS29uZyd9LAogICAgJ0FsbGVuLkhlQGFlaS5jb20nID0+ICAgICAgICAgICAgICB7J0NpdHknID0+ICdaaG9uZ3NoYW4nLCAnQ291bnRyeScgPT4gJ0NoaW5hJywgJ1RpbWVab25lJyA9PiAnQXNpYS9Ib25nX0tvbmcnfSwKICAgICdBbmdlbC5XYW5nQGFlaS5jb20nID0+ICAgICAgICAgICAgeydDaXR5JyA9PiAnWmhvbmdzaGFuJywgJ0NvdW50cnknID0+ICdDaGluYScsICdUaW1lWm9uZScgPT4gJ0FzaWEvSG9uZ19Lb25nJ30sCiAgICAnQ2xpZmYuWmhhbmdAYWVpLmNvbScgPT4gICAgICAgICAgIHsnQ2l0eScgPT4gJ1NoZW56aGVuJywgJ0NvdW50cnknID0+ICdDaGluYScsICdUaW1lWm9uZScgPT4gJ0FzaWEvSG9uZ19Lb25nJ30sCiAgICAnRGVjbGFuLlBvcnRlckBhZWkuY29tJyA9PiAgICAgICAgIHsnQ2l0eScgPT4gJ0hvbmdrb25nJywgJ0NvdW50cnknID0+ICdDaGluYScsICdUaW1lWm9uZScgPT4gJ0FzaWEvSG9uZ19Lb25nJ30KfTsKCi8vIEZldGNoIGNvbnRhY3RzIGNyZWF0ZWQgKip0b2RheSoqCkxpc3Q8Q29udGFjdD4gcmVjZW50Q29udGFjdHMgPSBbU0VMRUNUIElkLCBGaXJzdE5hbWUsIExhc3ROYW1lLCBFbWFpbCwgQWNjb3VudElkIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZST00gQ29udGFjdCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC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