Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-01-2013 06:24 PM
I have a map that is Map<string, id> I want to get the information from the map. I have a variable that will have the key information thatI want to get from the map. If I put map.get(variable) I get a return of Null. If I put map.get('12345') I get the correct result. 12345 is the information in the map. If I use system.debug it shows that my variable has 12345. Any idea why if I use a variable in the map.get(HERE) I do not get a result?
Solved! Go to Solution.
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-01-2013 10:46 PM
Hi,
Can you show the key, value combination and how you are creating it?
Re: Apex Map help
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 08:06 AM - edited 01-02-2013 08:07 AM
for(product2 p : pl){
prodMap.put(p.name, p.id);
}for (integer i=1; i<filelines.size();i++){
list<string> values = new list<string>();
values = filelines[i].split(',');
OrderLine__c o = new OrderLine__c();
o.ShipToAddress__c=oLine.ShipToAddress__c;
o.PartNumber__c = prodMap.get(values[1])Filelines splits a csv file that has been imported.
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-04-2013 05:19 PM
Assuming that 'values' is an array where the second position (that is, index elm = 1) is a Product2.name, then the prodMap.get(..) statement will work provided there are no case sensitive issues between the input and what you fetch from SFDC
Problems like this are readily resolvable with system.debug() - you can verify that prodMap contains all the entries you expect and then compare against values[1]
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-07-2013 07:27 AM
crop1645 wrote:Assuming that 'values' is an array where the second position (that is, index elm = 1) is a Product2.name, then the prodMap.get(..) statement will work provided there are no case sensitive issues between the input and what you fetch from SFDC
Problems like this are readily resolvable with system.debug() - you can verify that prodMap contains all the entries you expect and then compare against values[1]
This is the bizarre thing to me. When I use the system.debug I get 115630 as values[1] and 115630 is one of the keys in the map, but prodMap.get(values[1]) returns null. On the other hand if I put prodMap.get('115630') that returns the correct result.
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-07-2013 09:44 AM
Scott -- are you sure that values[1] doesn't have a leading or trailing space, NBSP, or other unprintable character?
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-08-2013 08:47 AM
Thats a thought. I could use deleteWhitespace on both sides of it to eliminate that as an issue. I will give that a try and let you know. thanks for the help.
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-08-2013 08:56 AM
I added the deleteWhitespace to the put and get parts of the map but it still did not work. Any other ideas?
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-08-2013 03:48 PM
I think I found it. I think there is a return at the end of the number. Any idea how I can get rid of that?
Re: Apex Map help
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-08-2013 05:44 PM
Good for you -- I really appreciate your persistence and willingness to resolve things yourself
I was going to suggest displaying the values in hex to see the errant characters
You're going to need to do something like this
searchString = values[1].replaceAll('\n','').replaceAll('\r',''); // be sure values[1] isn't null

