You need to sign in to do that
Don't have an account?
Abhishek AS 3
Retrieve accounts related to contacts whose contact name contains word 'test'
I have a requirement in which i have to retrieve accounts related to contact where contact name matches the keyword entered by user.
string keySearch = '%' + 'T' + '%';
List<Contact>conList=[SELECT Name,AccountId FROM Contact WHERE Name LIKE: keySearch];
List<Account>accList= new List<Account>();
for(Contact con: conList){
if(con.AccountId!=null){
accList=[Select id,Name, Industry From Account where id =: con.AccountId];
}
}
system.debug(conList);
system.debug(accList);
Its not working properly
string keySearch = '%' + 'T' + '%';
List<Contact>conList=[SELECT Name,AccountId FROM Contact WHERE Name LIKE: keySearch];
List<Account>accList= new List<Account>();
for(Contact con: conList){
if(con.AccountId!=null){
accList=[Select id,Name, Industry From Account where id =: con.AccountId];
}
}
system.debug(conList);
system.debug(accList);
Its not working properly
Can you try the below logic.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
You need the Accounts whose contact name is like searchkey?
Thanks,
Can you try the below logic.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,