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
Charles McDowellCharles McDowell 

I have the following code to create a map that is returned to a class. I can not retrieve the values

public class RetrievePrice {
   Public Static Map<String , Double>  UtilPrice(){
      List<Utility_Price__c> upp =[Select Price_Type__c, Price__c From Utility_Price__c ];
          Map<String, Double> pMap = new Map<String, Double>();         
    {    
    for (Utility_Price__c p :upp){
            pmap.put(p.price_type__c, p.Price__c);
            system.debug('The price is:' + p.Price__c);        
    }
            Return pmap; 
  
    }
}
}

public class createInvoice{
    static Map<String, Double> Price = new Map<String, Double>();
        createInvoice(){
        Price = RetrievePrice.UtilPrice();
}
}
How do I reference the values in the map
sfdcMonkey.comsfdcMonkey.com
hi Charles McDowell 
make your class constructor public
public class createInvoice{
    static Map<String, Double> Price = new Map<String, Double>();
       public createInvoice(){
        Price = RetrievePrice.UtilPrice();
}
}
thanks
let me inform if it helps you

 
Amit Chaudhary 8Amit Chaudhary 8
Update your Code like below
public class RetrievePrice 
{
    Public Static Map<String , Double>  UtilPrice()
    {
		List<Utility_Price__c> upp =[Select Price_Type__c, Price__c From Utility_Price__c ];
		
		Map<String, Double> pMap = new Map<String, Double>();         
		
		for (Utility_Price__c p :upp)
		{
				pmap.put(p.price_type__c, p.Price__c);
				system.debug('The price is:' + p.Price__c);        
		}
		Return pmap; 
	}
}
 
public class createInvoice
{
    public Map<String, Double> Price = new Map<String, Double>();
	public createInvoice()
	{
        Price = RetrievePrice.UtilPrice();
	}
}
Let us know if this will help you