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
Ramana123Ramana123 

I am not able to access the map values (Highlighted Line error)

global class Updating_MembershipSalesLines1 implements Schedulable {
    global void execute(SchedulableContext ctx) {
    
     Map<String,List<membership_sales_lines__c>> lineRelatedRecords = new Map<String,List<membership_sales_lines__c>>();       
     List<membership_sales_lines__c> memberShipRecords = [Select Id,Name,Payment_status__c,Ledger_entry_no__c from membership_sales_lines__c where Payment_status__c !='Paid'];
     for(membership_sales_lines__c sales : memberShipRecords) {
            String salesOrder = sales.Name;
            List<membership_sales_lines__c> accOppList = lineRelatedRecords.get(salesOrder);
            
            if(accOppList == null) {
                lineRelatedRecords.put(salesOrder,new List<membership_sales_lines__c>{sales});
            } else {
                lineRelatedRecords.get(salesOrder).add(sales);
            }
        }        
            List<membership_sales_lines__c> paidStatusRecords = new List<membership_sales_lines__c>();
            paidStatusRecords = [select Id,Name,Payment_status__c,Ledger_entry_no__c from membership_sales_lines__c where Payment_status__c = 'Paid'];
            
            for(membership_sales_lines__c  obj : paidStatusRecords)
            {
                if(lineRelatedRecords.containsKey(obj.Name))
              {
                       obj.Payment_status__c = lineRelatedRecords.get(obj.Name).Payment_status__c ;
              }
            }  
 
Vishwajeet kumarVishwajeet kumar
Hello,
From Code it looks like first List - memberShipRecords contains records with criteria Payment_status__c !='Paid' VS 2nd one paidStatusRecords which contains records with criteria Payment_status__c ='Paid'. So their will be no match of records i think and program will not reach at line in question.

What error are you getting?

Thanks
Ramana123Ramana123
hii viswajeet I am comparing the name filed in both the lists , so if the names will exits in both the lists . but the error on this line is * ---- obj.Payment_status__c = lineRelatedRecords.get(obj.Name).Payment_status__c ;* Payment_status__c variable not exist
Vishwajeet kumarVishwajeet kumar
Hello,
Ok i see. i think i know why it is failing : 
lineRelatedRecords.get(obj.Name) returns a List<membership_sales_lines__c>, which is a List of values. Implement logic to get any particular value from List if you are looking for.

if you are just looking for first item use index [0] as below : 
obj.Payment_status__c = lineRelatedRecords.get(obj.Name)[0].Payment_status__c 

Thanks