function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rohit.mehtarohit.mehta 

Schema.SObjectType.Opportunity.fields.getMap() Returns Empty Map

Hi,

I want to be able to get all the fields for the Opportunity. I am writing custom code for cloning an opportunity.
I had the following piece of code which was working but suddenly has stopped working.

Code:
        Map<String, Schema.SObjectField> m = Schema.SObjectType.Opportunity.fields.getMap();
        System.debug('isEmpty = ' + m.isEmpty());

This now returns an empty map.
Any ideas why this call would return an empty map.

Thanks,
Rohit

Best Answer chosen by Admin (Salesforce Developers) 
rohit.mehtarohit.mehta
Thanks.
It was the API restriction.

Rohit

All Answers

gregsgregs
you should try to run this code in the system log anonymous window to see if it works there.  if not, it could return an empty map if the package you have this code in does not have explicit permissions for access to the opportunity object... you can check this by going to the create package and looking at the api access  status near the top...
rohit.mehtarohit.mehta
Thanks.
It was the API restriction.

Rohit
This was selected as the best answer
mshelmanmshelman
We are having the same problem only the sobject  in question is a custom object  that is included in the package and therefore the package permissions should not  be needed. The package is set to No Restrictions. Any help?

Prev message here

Mike
naresh reddy 18naresh reddy 18
HI Good Day..

    I am facing the same problem. Any one have any solution?

Thanks,
Naresh



 
naresh reddy 18naresh reddy 18
HI,

  I solved the problem. Pls open the your managed package detail page in "Installed Packages" menu. The check the API Access option. That should be unrestricted.

Thanks,
Naresh