0

I have an apex class where I need to catch the picklist values based on each lead id but right now it is catching all the picklist values for all Id's and storing.

Can anyone helps me out in this issue here if possible.

my class is below:

if(noParentLeadList != null && noParentLeadList.size() > 0){
        Map<Id,List<Contact>> insertConMap1 = createContactNoParent(noParentLeadList);
        List<String> primaryprogram =new List<String>();
        Set<String> secondaryprogram = new Set<String>();
        for(Id idKey : insertConMap1.keySet()){
            insertConList1.addAll(insertConMap1.get(idKey));
        }
        insert insertConList1;
        for(Lead l2:noParentLeadList){
            if(l2.What_is_your_primary_program_of_interest__c != null){
                primaryprogram.add(l2.What_is_your_primary_program_of_interest__c);
            }
            if(l2.Other_Programs_of_Interest__c != null){
                secondaryprogram.addAll(l2.Other_Programs_of_Interest__c.split(';'));
            }
        }
        for(Id IdKey : insertConMap1.keySet()){
            //creates affiliation record for primary program
            if(primaryprogram != null){

                Map<String,Id> accNamesToIdsMap2 = new Map<String,Id>();
                for(Account acc : [select id,Pardot_Program_Name__c from account where Pardot_Program_Name__c in : primaryprogram]){
                    accNamesToIdsMap2.put(acc.Pardot_Program_Name__c,acc.Id);
                }

                for(Id accId : accNamesToIdsMap2.values()){
                    insertaffiliationList1.add(new hed__Affiliation__c(hed__Account__c= accId,
                                                            hed__Contact__c=insertConMap1.get(IdKey).get(0).Id,
                                                            hed__Primary__c = true,
                                                            hed__Role__c='Prospect'));
                }
            }
            //Creates affiliation record for other programs of interest
            if(secondaryprogram != null){
                Map<String,Id> accNamesToIdsMap3 = new Map<String,Id>();
                for(Account acc : [select id,Pardot_Program_Name__c from account where Pardot_Program_Name__c in : secondaryprogram]){
                    accNamesToIdsMap3.put(acc.Pardot_Program_Name__c,acc.Id);
                }
                for(Id accId : accNamesToIdsMap3.values()){
                        insertaffiliationList1.add(new hed__Affiliation__c(hed__Account__c= accId,
                                                        hed__Contact__c=insertConMap1.get(IdKey).get(0).Id,
                                                        hed__Role__c='Prospect'));
                }
            }

        }
        insert insertaffiliationList1;
2
  • Where is problem? Can you point out line no? – Dhanik Lal Sahni Aug 1 '19 at 14:38
  • @DhanikLalSahni,actually for each lead record I will have one value in What_is_your_primary_program_of_interest__c, so for one contact, one affiliation record should get created but if I insert 3 records using data loader then my class is catches picklist valuea of all 3 records and creating 3 Affiliation records for each contact record but basically it should create only one for each contact record bcoz on every lead I will select only one value in picklist – Sainath Aug 1 '19 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.