+1 vote
by (163k points)

I am trying to populate Account Type on Contact by creating custom picklist 'Type' using Maps.


public class ContactAccountMap {
    public void accountMap() {
        Set<Id> accountIds = new Set<Id>();
        List<Contact> conList = [SELECT Id, Name, Type__c, AccountId FROM Contact];
        for(Contact con : conList) {
        List<Account> accList = [SELECT Id, Name, Type FROM Account WHERE Id IN:accountIds];
        Map<Id,Account> accMap = new Map<Id,Account>([SELECT Id, Name, Type FROM Account WHERE Id in:accountIds]);
        for(Contact con : conList) {
            if(con.AccountId != NULL) {
                con.Type__c = accMap.get(con.AccountId).Type;

The code doesn't throw any errors but the I am not getting the functionality. Can someone help me with this...

Thanks in advance...

1 Answer

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.