You need to sign in to do that
Don't have an account?
Mack Dsoza
Not getting key value in Map
If I am not getting any key as well as values from Map then please tell me that what are the things that needs to be checked.
Here is my map code,
Map<Id,asset__c> & here I am not getting any key value so what I have to do for it..
Regards...
Giving us the map type is not enough information. I'm assuming from this post that your map is empty when you come to process it. You'll need to post the code that populates the map in order for us to suggest anything.
I second Bob, your req is not clear. But if you talking about checking that a particular value exists in map of not then here is the code :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
public class AssetAllocationBean {
public MAP<ID,Asset__c> assetMap {
get {
if(assetMap == null) {
assetMap = new Map<ID,Asset__c>();
}
return assetMap;
}
set;
}
}
This is my bean class which is taking values but I am confuse in bean concept whether bean accpets or sets values only from VFpage or it can accepts or sets values from database too..
If it accepts values from database too so that how to assign value into bean with database values.
Your bean will accept values from both the page and the database, but only if you extract those values and set them into the map. Are you expecting some sort of automatic population of the map?
Yaa exactly Bob, actually on click of save button it should create map which will store the values of all my custom object so that I can use that values in another form.
If I want to populate values in this bean then what i have to do ?
You'll have to come up with the key/value pairs and add them to the map.
Something like:
where you replace the key1/value1 literals with the actual values you want to store.
But if i want to access values from database then what i have to do for that.
Since i am working on three classes as, ControllerClass, BeanClass & ServiceClass.
Controller just handles action
Bean Initializes a fields
Service holds my entire business logic
So also tell me where should i write my code to put values in map...
Regards...
You can populate a map with a database query as follows:
Replacing the rather basic SOQL query with your own requirement.
Since I have made entire things according to MVC pattern....
I have written these function to get assetMap
private Map<ID,Asset__c> getAssetMap(String entityId) {
Map<ID,Asset__c> assetMap = new Map<ID,Asset__c>();
try {
List<Asset__c> assetList;
// Gets values from Database object...
assetList = databaseObj.getAssets(entityId);
for(Asset__c asset : assetList) {
assetMap.put(asset.Id,asset);
}
}catch(Exception ex) {
throw new GeneralException('AssetAllocationService.getAssetMap : Internal Error ' + ex.getMessage());
}
return assetMap;
}
But nw the problem is how to assign this returning value to my bean or since i added the value in it so will it get automatically assign..or is there any mistake in my above mentioned code.
You can assign the contents of one map to another using the putAll method.
E.g.
Getting an error...
Error: NewAssetAllocationController Compile Error: Method is not visible: [AssetAllocationService].getAssetMap(String) at line 17 column 35
This sounds like your method is private and needs to be made public so that other classes can access it.
I created instance of my Bean class then printed value of that instance...& I am getting all value as null.
So can u tell me wht mistake i am doing ?
Fetch asset allocation bean value is : AssetAllocationBean:[assetMap=null, assetRecordTypeBeanList=null, goalAssetAssociationMap=null, goalInsuranceAssociationMap=null, goalInvAssetAssociationMap=null, headerList=null, insuranceMap=null, investmentAssetMap=null]
Have you assigned the value to the beans.
I have sent code to you through private message.
So check that code, As I think that might be problem in my assignment of the value bt I am nt getting it so please tell me the solution.
But according to me that I have written/assign in bean but u also chk that...
You'll need to post your code on here I'm afraid. It doesn't add to the knowledge if we go offline part way through.
There's also a lot of code there - can you just post the important parts for now.
Where are you creating your AssetAllocationBean records and setting up the assetmap? I can't see anything in that code that is populating the map.
I am also not getting why it is not accessing,
Since it is not getting values so can u please tell me from where it is trying to fetch values or general idea that whenever I create get & set method then from where it fetches values so that i can try to solve it..
Is their any idea to fill values in it so that porblem will get solved..
Presumably you have some code in your system that is creating an AssetAllocationBean?
As there isn't any code in the bean itself to populate the assetMap, should you be setting up the assetMap when you create it? If not, how are you planning to set the values?
Can u just give me an idea or little bit code to initialize my bean.
As i am doing that I have created getAssetMap method in controller which put the key & values in it...
Following is the code...
But tell me also that it is returning value as assetMap & redmarked text will not assign the value...
/*
Asset Map is holding ALL assets for any given parent and its child entities
*/
private Map<ID,Asset__c> getAssetMap(String entityId) {
Map<ID,Asset__c> assetMap = new Map<ID,Asset__c>();
try {
List<Asset__c> assetList;
assetList = databaseObj.getAssets(entityId);
for(Asset__c asset : assetList) {
assetMap.put(asset.Id,asset);
}
}catch(Exception ex) {
throw new GeneralException('AssetAllocationService.getAssetMap : Internal Error ' + ex.getMessage());
}
return assetMap;
}
@Bob Don't give up please :)
Thanks
Ankit Arora
Blog | Facebook | Blog Page
The assetMap that you are putting the values into is not the same assetmap as that stored in your bean is it?
The redmarked text assigns to the local assetMap to the method. Which class is this method from?
Actually that method named getAssetMap is in my service class.
Actually We have created with MVC pattern,
And which of these should be writing the assetMap information into the bean class?
In this, service class has method as getAssetMap method which is fetching values from DBSOQL class.
& it is returning values as assetMap.
Since it is returning values so it will directly will get assign to Bean..
Bcoz whenever we write any get & set method named account so when we write getAccount & return its value as account then its value gets assigned to Bean...
But your service class has a getter that instantiates a new map and returns that - it doesn't store any information elsewhere in either that class or the bean class.