You need to sign in to do that
Don't have an account?

Map of API name and value pair..?
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap(); Opportunity opp=[Select id,name,accountId from Opportunity]; Map<String,string> valueMap=new Map<String,String>(); for(opportunity o:opp) { for(String fieldName: fieldMap.keySet()) { **valueMap.put(fieldName,o);** } }
I want to create a map of apiname and value pair..please help...
i want record value...like if apiname of opportunity field is name..then i want record value..ie opportunity name...
try this
Map<String,opportunity> valueMap=new Map<String,opportunity>();
for(opportunity o:opp)
{
for(String fieldName: fieldMap.keySet())
{
**valueMap.put(fieldName,o);**
**valueMap.put(fieldName,o.name);**//in this dont change u map it will remain(string,string)
}
}
All Answers
Try this.
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks
try this
Map<String,opportunity> valueMap=new Map<String,opportunity>();
for(opportunity o:opp)
{
for(String fieldName: fieldMap.keySet())
{
**valueMap.put(fieldName,o);**
**valueMap.put(fieldName,o.name);**//in this dont change u map it will remain(string,string)
}
}
@Miku - This should be what you are after I guess, assuming you are try to setup a map of field names v/s opportunity object field values. Replace your astericked line:
with this
Do mark this as a solution if this helps and KUDOS would be the way to go....
Regards
vbs
I'm having trouble generating the fieldMap - what is leadSchema?
objname here is name of any object...may selected from picklist on vf page..
Let me know if you have any issue..
here is sample code...
Thanks!
Instead of
valueMap.put(fieldName,o.get(fieldName));
I used:
valueMap.put(fieldName,string.valueof(o.get(fieldName)) );
To avoid type mismatch.
yeah..cheers it worked for you...
Well, I'm still having problems. Message:
SObject row was retrieved via SOQL without querying the requested field: Opportunity.PROSP_SRC_DESC__c
An unexpected error has occurred. Your development organization has been notified.
Here are the exact items I'm using:
1. Apex Controller - ApiValueMapMaker.cls:
2. Visualforce page - ApiValueMapMakerDisplay.page:
<apex:page standardcontroller="Opportunity" extensions="ApiValueMapMaker">
Map is:
<br/>
{!ValueMap}
</apex:page>
Then, I called it via:
/apex/ApiValueMapMakerDisplay?id=*** opportunity SFDC ID goes here ***
When I replaced the getRecord() (from the ?id=... on the page), to a SELECT .... LIMIT 1, I still get the error message.
Thanks,
You need to make query dynamic..as you are not adding all the fields in your query
try this...
or try adding all the fields in your query...it will work....
let me know if it works...