You need to sign in to do that
Don't have an account?
Akash Choudhary 17
I want to move new contacts to the matching accounts based on domain. Contact Email should match the account's domain
Hi all,
Here is my code though its not showing any error but I am certain there is someting wrong with it. As it is not fulfilling the requirement.
Please help me rectifying it. and let me know where I am goung wrong.
public class Move_Contact {
public static void updateContact(List <Contact> conList){
String MainDomain = '';
string website ='www' +MainDomain;
string httpWebsite ='http://www' + MainDomain;
string httpswebsite ='https://www'+ MainDomain;
string international = MainDomain + '.%';
for(Contact myCon : conList){
if(myCon.Email != null){
string domain = myCon.Email.split('@').get(1);
MainDomain = domain;
}}
Map <Id,Id> conMap = new Map <Id,Id>();
for(Contact myCon : conList){
conMap.put(myCon.Id , mycon.AccountId);
}
List<Account> acc = [SELECT Id
FROM Account
WHERE Website =:website
or Website =:httpWebsite
or Website =:httpswebsite
or Website =:international];
if(acc.size() == 1){
For(Contact c : conList){
acc.get(0).Id = conMap.get(c.Id);
c.AccountId = conMap.get(c.Id);
}
}
}
}
Here is my code though its not showing any error but I am certain there is someting wrong with it. As it is not fulfilling the requirement.
Please help me rectifying it. and let me know where I am goung wrong.
public class Move_Contact {
public static void updateContact(List <Contact> conList){
String MainDomain = '';
string website ='www' +MainDomain;
string httpWebsite ='http://www' + MainDomain;
string httpswebsite ='https://www'+ MainDomain;
string international = MainDomain + '.%';
for(Contact myCon : conList){
if(myCon.Email != null){
string domain = myCon.Email.split('@').get(1);
MainDomain = domain;
}}
Map <Id,Id> conMap = new Map <Id,Id>();
for(Contact myCon : conList){
conMap.put(myCon.Id , mycon.AccountId);
}
List<Account> acc = [SELECT Id
FROM Account
WHERE Website =:website
or Website =:httpWebsite
or Website =:httpswebsite
or Website =:international];
if(acc.size() == 1){
For(Contact c : conList){
acc.get(0).Id = conMap.get(c.Id);
c.AccountId = conMap.get(c.Id);
}
}
}
}
Check your account list in system.debug to make sure whether your query returning records or not because i think you are making mistake in assinging values to website,httpwebsite,httpswebsite and international variables and also you are not updating contact list after assigning accountid to it...
https://salesforce.stackexchange.com/questions/70539/assign-account-to-contact-based-on-email-domain
Here is the sample code .. bulkfy this code pls
The formula.
The Apex code
Your is working but when I am bulkiying this, then its not . please help
Hi Steven,
I wanted to do this without any custom field but thanks anyway