Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Why getting an Invalid initializer error?

Asked by Anisha Dalal Apr 16, 2021 743 views 1 answer
Share

About this question

In my custom object, I have two fields Name__c and QuestionString__c

I am trying to initialize a map with Name__c as key and QuestionString__c as a value from a SOQL.

Map ppmap = new Map([SELECT Name__c, QuestionString__c FROM PObj__c]);

I tried the above but I get the error as

Invalid initializer type List found for Map: expected a Map with the same key and value types, or a valid SObject List

Can someone tell me if it is possible to initialize a map directly (without "Id") from SOQL?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.