function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yoni LegacyYoni Legacy 

Insert Class is not working..


Can somedoby help me to make my code work? I am really new in development and none is mentoring me. I tried my best to make the code below work but it's not working.. It's not creating Account List.

Here is my code.
public with sharing class InsertAccountListRec_TEST_cls {
	Set<Id> allParentRecsSet = new Set<Id>();
    Set<Account_List_vod__c> accRecSet = new Set<Account_List_vod__c>();
    List<Affiliation_vod__c> allAffParentRecs = new List<Affiliation_vod__c>();
    List<Account_List_vod__c> newAccListRecList = new List <Account_List_vod__c>();
    Map<Id,Id> mapAffRecs = new Map<Id, Id>();
    Map<Id, String> acctListMap = new Map<Id,String>();
	Map<String,Id> mapAffOwner = new Map<String,Id>();
    //Creation a list of all Parent Affiliation Records, then add to allParentRecsSet (SET).
    //Start of 1st Block
    public List<Affiliation_vod__c> getParentAffRecs(){
        allAffParentRecs = new List<Affiliation_vod__c>([SELECT Id, From_Account_vod__c, To_Account_vod__c,Business_Account__c 
                                                         FROM Affiliation_vod__c
                                                         WHERE (From_Account_vod__r.Id = '0011200001GNrb0AAD' 
														 AND Parent_vod__c = True)
														 AND OwnerId IN (SELECT Id
																				FROM User
																				WHERE (Profile_Name_vod__c LIKE '%Eisai_Epilepsy%' 
																				OR Profile_Name_vod__c LIKE '%Eisai_PrimaryCare%') 
																				AND IsActive = TRUE)]);
		System.debug('Parent Affiliation record count '+ allAffParentRecs.size());																					
        //Iterate on the Affiliation records (Group Practice Accounts) 
        //If the From_Account_vod__c field has a value (meaning: Not blank), add the value to allParentRecsSet (SET)
       allParentRecsSet = new Set<Id>();
        for(Affiliation_vod__c aParentRecs: allAffParentRecs){
            if(aParentRecs.From_Account_vod__c != Null){
                mapAffRecs.put(aParentRecs.Id, aParentRecs.From_Account_vod__c); 
        return allAffParentRecs;
    }//end of 1st block
	//Start of 2nd block
    //For every Parent Affiliation record inside the affParentRecsLst, check if the accRecSet (Set) doesn't contains Account List records,
    // -->If true, add the Account List Record to accRecSet (SET) and put into acctListMap (MAP).
	//Pass the Account List records from accRecSet (SET) to newAccListRecList (LIST).After that,Insert the records inside the newAccListRecList (LIST)
    public Map<Id, String> createAcctListRecs(){
        acctListMap = new Map<Id,String>();
        accRecSet = new Set<Account_List_vod__c>();
        for(Affiliation_vod__c allParentAffRecs : allAffParentRecs){
            Account_List_vod__c newAccListRec = new Account_List_vod__c();    
            newAccListRec.Name = 'HO_' + mapAffRecs.get(allParentAffRecs.Id); 
            newAccListRec.Icon_Name_vod__c = '0';	
			newAccListRec.OwnerId = mapAffOwner.get(allParentAffRecs.Name);
                acctListMap.put(newAccListRec.Id, newAccListRec.Name);
            for(Account_List_vod__c acctListRecs : accRecSet){
                System.debug('Account List records to be created ' + newAccListRecList);
            insert newAccListRecList;     
        return acctListMap;
    }//end of n2d block	


Thanks in advance to your help.