I want to get a map of rate_code and ID instead of Id and Rate object directly from SOQL query.  If i run following query then i will have to iterate over rateMap map to create Map&lt;String rate_code , String ID&gt;. Is there any other efficient way to get this kind of result directly using soql OR by doing minimal manipulations in apex code ?  Map&lt;String, Rate&gt; rateMap = [select id, rate_code from Rate];
37684
I'm trying create a Map using a name field as key.  Sample code:  Set&lt;String&gt; priceBooksNames = new Set&lt;String&gt;(); priceBooksNames.add('LN-200'); priceBooksNames.add('LN-100');  Map&lt;string,PriceBook2&gt; priceBooks = new Map&lt;string,PriceBook2&gt;([SELECT name,id FROM PriceBook2 WHERE name=:priceBooksNames ]); system.debug(priceBooks.get('LN-100')); //this is returning NULL   I can see on console that setId on map is not getting the name field value.  VARIABLE_ASSIGNMENT [5]|priceBooks|{"serId":1,"value":{"01sb0000000hiqQAAQ":{"serId":2,"value":{"Name":"LN-100 ADULTOS","Id":"01sb0000000hiqQAAQ"}},"01sb0000000hiqGAAQ":{"serId":3,"value":{"Name":"LN-200 EMPRESAS","Id":"01sb0000000hiqGAAQ"}}}}   What I'm going wrong?
118273
I'm trying to parse json response.. but keep getting this error      Invalid conversion from runtime type List ANY> to Map String,ANY>   Map&lt;String, Object&gt; MapLv3 = new Map&lt;String, Object&gt;();      Integer x2 = 0; for (Object oh : CallsList){     MapLv3.put(String.valueof(x2), oh);     x2++; } index = x2; System.debug('Map Lv 3 ==&gt;'+MapLv3);  Map&lt;String, Map &lt;String, Object&gt;&gt; Map3 = new Map&lt;String, Map &lt;String, Object&gt;&gt;(); for (Integer a2 = 0; a2 &lt; index; a2++){     Map3.put(String.valueof(a2),(Map&lt;String,Object&gt;) MapLv3.get(String.valueof(a2))); } System.debug('Segment ==&gt;'+Map3.get('0').get('segments'));
15035
Can some one correct my soql? I need to export records in data loader like:  WHERE Id IN ('123123123','123123fsdf')   But this following query does not work for me:  SELECT Id, Syndication_Documents__c FROM ContentVersion  WHERE Syndication_Documents__c in : 'a4fa0000000KzbV','a4fa0000000KzbW'
22371
I write a sample query to fetch account Ids from cases of a particular record type.Then i wrote another sample query parent to child relationship to fetch opportunity ids from accounts.  My sample code  List&lt;Case&gt; c=new List&lt;Case&gt;(); c=[Select Id,accountId from case where RecordTypeId = '01290000000sF3L']; List&lt;Id&gt; accountIds= new List&lt;Id&gt;(); List&lt;Account&gt; accounts=new List&lt;Account&gt;(); List&lt;Opportunity&gt; opps=new List&lt;Opportunity&gt;(); for(Case cl:c)  { accountIds.add(cl.accountId); } accounts=[Select Id,name,(select Id,name from opportunities) from account        where Id in:accountIds]; System.debug('Data in accounts '+accounts);   But my issue is how to get opportunity id from above Soql accounts means how to add those opportunity id's to the list.  for(Account ao:accounts) { //How to fetch Opportunity ids from above account list. }
113237
I am running a soql query to obtain the value of a specific field from a custom object and it is returning the ID of the record on the visualforce page instead of the field value that I need it to return, the specific query I am having issues with is the Names query on the very bottom. If anyone has any ideas why it's returning the ID of the record instead of the specific field value please let me know.   patient_name__c is the field name that I need to obtain the value from and lead__c is a custom object that we have created.       public without sharing class LeadAlertController {     public integer leads {get;set;}     public integer overleads {get;set;}     public List&lt;lead__c&gt; Names {get;set;}         public LeadAlertController() {         leads = [select count() from lead__c where lead_status__c=:'Not Attempted'];         overleads=[select count() from lead__c where lead_status__c=:'Not Attempted' AND x10MinAlert__c=:true];         Names = [select patient_name__c from lead__c where lead_status__c=:'Not Attempted'];       } }   Here is my VF Page  &lt;apex:page controller="LeadAlertController" showHeader="false" sidebar="false" standardStylesheets="false"&gt; &lt;!-- Begin Default Content REMOVE THIS --&gt; &lt;meta http-equiv="refresh" content="10"/&gt; &lt;style&gt; td{     border: 1px ;     border-style: solid; } &lt;/style&gt; &lt;table align="center" style="width:100%;border:1px solid"&gt;     &lt;tr&gt;         &lt;td align="center"&gt;             &lt;h3&gt;Number of Hot Leads&lt;/h3&gt;         &lt;/td&gt;         &lt;td align="center"&gt;             &lt;h3&gt;Number of Hot Leads Over 10 Minutes&lt;/h3&gt;         &lt;/td&gt;          &lt;td align="center"&gt;             &lt;h3&gt;List of Names&lt;/h3&gt;         &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;         &lt;td align="center"&gt;             &lt;h1&gt;{!Leads}&lt;/h1&gt;         &lt;/td&gt;         &lt;td align="center"&gt;             &lt;h1&gt;{!OverLeads}&lt;/h1&gt;         &lt;/td&gt;          &lt;td align="center"&gt;             &lt;h1&gt;{!Names}&lt;/h1&gt;         &lt;/td&gt;     &lt;/tr&gt; &lt;/table&gt;  &lt;apex:outputPanel rendered="{!if(OverLeads&gt;0,true,false)}"&gt;     &lt;audio src="/resource/alert" type="audio/mp3" autoPlay="true"&gt;     &lt;/audio&gt; &lt;/apex:outputPanel&gt;
52986
I am trying to add map of map values, I have to intialize the map key first and then try to add value later. Below is the exact logic i am trying to achieve.  Map&lt;string,Map&lt;string,List&lt;string&gt;&gt;&gt; finalMap = new Map&lt;string,Map&lt;string,List&lt;string&gt;&gt;&gt;();  Map&lt;string,List&lt;string&gt;&gt; subMap = new Map&lt;string,List&lt;string&gt;&gt;(); submap.put('One',new list&lt;string&gt;{'One','TWO'});  finalMap.put('SUB1',new Map&lt;string,List&lt;string&gt;&gt;());  //Do some logics and finally try to add the values with the key  finalmap.get('SUB1').put(subMap); //Error as stated below  System.debug(finalmap);      ERROR :Method does not exist or incorrect signature:   [Map&lt;String,List&lt;String&gt;&gt;].put(Map&lt;String,List&lt;String&gt;&gt;)
56570
I have a database table that looks like:   create table answers(    id int not null,    question_id int not null,    answer text null )   This table was originally build by Hibernate using the @Lob attribute for the "answer" column.  I did not realize it at the time, but when setup that way, Hibernate stores an OID in the column instead of the actual text.  Everything works fine when I use Hibernate to retrieve the values since it automatically converts the OID to the CLOB string, however it is becoming a performance problem and I'd like to get rid of the OID.   select * from answers ID     QUESTION_ID     ANSWER =============================== 1       123             55123 2       234             51614 3       345             56127 should be ID     QUESTION_ID     ANSWER =============================== 1       123             Male 2       234             203-555-1212 3       345             555 Main St. New York, NY    My desire is to add an extra column to the table "ANSWER_VALUE TEXT" and do something like below to get the actual value into the table, then change Hibernate around to not use the @Lob designator   update answers set ANSWER_VALUE= getValueFromOID(ANSWER)   Does that "getValueFromOID" function exist?  If not, could I get some pointers on how to create one or at least how to fetch the actual value of an OID?  Thanks
61444
I'm trying to build a Dynamic list(table) of records by selecting the Sobject and its fields.So I need to get all the fields with its API name,label,type.But I can't get the label and type.(Tried DescribeSObjectResult Class methods to get label,but it didn't help to get the label dynamically)  I tried it with the following code.  System.debug('Selection-----'+selectedObject); Map&lt;String, Schema.SObjectType&gt; gd = Schema.getGlobalDescribe();  Schema.SObjectType ctype = gd.get(selectedObject);  Map&lt;String, Schema.SobjectField&gt; fmap = ctype.getDescribe().fields.getMap();    List&lt;FieldWrap&gt; strList = new List&lt;WrapMap&gt;(); for(String s: fmap.keySet()) {     WrapMap wmp = new WrapMap();     wmp.name = s;     wmp.label = String.valueOf(fmap.get(s));     strList.add(wmp);  }   Where FieldWrap is my wrapper class with name and field of String types. I'm getting the List of API name of fields,but not the Label and type of it.Is there a way to get the label and type of field.If so, please help me.
120029
I need to get some data based on a key field from multiple lists. For this, I may need to do multiple API calls. Is there any way to avoid this ? To get all the data from multiple lists in a single API call ?
38193
A type of the body is JSON Blob in a form of:  {"key1":"val1";"key2":"val2"}  I wanted to convert it into a Map&lt;String, String&gt;. Do I have to manually deserialize it or there's a class which can handle that?
40938
After I posted this question, I found a similar post that seemed to answer it: . I'll leave this in place for now, as I am not sure how to mark my own question as a duplicate  In attempting to debug a SOQL query error, I encountered a strange behavior with Database.query and bind variables. Specifically, when I run this code:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } Database.query(userQuery);   the Database.query statement executes with no errors, despite the fact that the variable firstNames does not exist in its context. However, when I add an else clause:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } else {     List&lt;String&gt; firstNames; } Database.query(userQuery);   I receive a null object reference exception. It seems like Salesforce is checking to see if the variable is only declared once beforehand and, if so, uses its value in the context it was declared. This seems strange to me, so I was wondering if anybody here has any insight into what is going on under the hood.
67051
I have created sObject and I need all the fields and I have many. Is there a way I can directly get all of them rather then typing each one of them.
1537
I know of two approaches to get the recordtype id of a particular record type   Use SOQL   RecordType RecType = [Select Id From RecordType  Where SobjectType = 'Account' and DeveloperName = 'Business'];    Benifit here is if the admin changes the name of the record type, the code still works as we can use developer name   Using Describe  Map&lt;String,Schema.RecordTypeInfo&gt; rtMapByName = d.getRecordTypeInfosByName(); Schema.RecordTypeInfo rtByName =  rtMapByName.get('Business');    Saves on SOQL limits but uses a describe call.  What would be your choice and why   EDIT : Usage is for setting up recordtype while inserting records in apex or trigger
17780
I am running this script from developer console.  List&lt;Account&gt; lstAccount = [SELECT Id, Name, BillingStreet From Account LIMIT 1]; System.debug(lstAccount);   Debug Log:     23:47:04:012 USER_DEBUG [5]|DEBUG|(Account:{Id=0019000001nNLGEAA4, Name=Acct_nm001, BillingStreet=xyz Road, RecordTypeId=01290000000iaNiAAI})   I never queried for RecordtypeId in SOQL, but it is included in the list.  Although, if I run the query from the query editor, it is not showing RecordtypeId column.   Is this by design? Then why not Salesforce is not providing us audit fields in the first scenario.
77562
I want to get the method System.Linq.Queryable.OrderyBy&lt;T, TKey&gt;(the IQueryable&lt;T&gt; source, Expression&lt;Func&lt;T,TKey&gt;&gt; keySelector) method, but I keep coming up with nulls.  var type = typeof(T); var propertyInfo = type.GetProperty(group.PropertyName); var propertyType = propertyInfo.PropertyType;  var sorterType = typeof(Func&lt;,&gt;).MakeGenericType(type, propertyType); var expressionType = typeof(Expression&lt;&gt;).MakeGenericType(sorterType);  var queryType = typeof(IQueryable&lt;T&gt;);  var orderBy = typeof(System.Linq.Queryable).GetMethod("OrderBy", new[] { queryType, expressionType }); /// is always null.   Does anyone have any insight? I would prefer to not loop through the GetMethods result.
42696
I want to write an Apex method that takes a country name as input and returns the equivalent two letter country code (ISO A2). Is there a way to write it without explicitly hard coding all countries and code in the method?
76771
Are there any governor limits, or considerations that I should be aware of when using Apex Describe methods?  So for example, the author of this blog post uses the structure below to get the record type instead of doing a soql query.     //Generate a map of tokens for the sObjects in your organization Map gd = Schema.getGlobalDescribe();  //Retrieve the describe result for the desired object DescribeSObjectResult result = gd.get('Account').getDescribe();  //Generate a map of tokens for all the Record Types for the desired object Map recordTypeInfo = result.getRecordTypeInfosByName(); system.debug('RECORD TYPES:' + recordTypeInfo);  //Retrieve the record type id by name String recordTypeId = recordTypeInfo.get('RECORDTYPE_NAME').getRecordTypeId();