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
mahesh padigela 1mahesh padigela 1 

I am new to salesforce,can someone please explain the exact reason why cant we use the wild charecter * in soql Query ?

Hi Mahesh,

Please see the link below:
Deepali KulshresthaDeepali Kulshrestha
Hi Mahesh,

Salesforce is a shared resource, which means that many tenants are using the system all at once. Also, some odd 80% of the traffic that Salesforce handles are actually from API calls, not Apex Code, Visualforce, or Lightning. As such, forcing developers to specify the fields they want to use helps alleviate API traffic so that things can flow smoothly. The limitations in Visualforce and Apex Code are important, but a relatively small portion of the resources used by the platform.

To see what I'm talking about, consider two queries that are run at the same time. The first queries two fields and returns 50,000,000 rows, and the second queries 500 fields and returns 50,000,000 rows. Statistically, this means that the second query will return 250 times more data than the first, and yet may use the same number of API calls. If Salesforce had a "select all field" operator, it would encourage lazy programming, potentially using hundreds of times more resources than necessary.

Note that one tenant can't directly affect another, but instead the aggregate is what's important. If you imagine a highway, it's easy to see if that if there are very few cars on the road, then everyone will get to go the speed they desire and reach their destination on time, but if a large number of huge trucks suddenly came on the highway, then all those trucks, and the smaller cars between, would all have to move slower to avoid accidents as the offramps became congested, causing a slow down for everyone.

To discourage this effect, everyone is forced to specify the fields that they want to use. Yes, there are still people that will try to query all the fields on a table at once, but they will be forced to use API calls to use field describes, and may also be forced to limit their query because of the 20,000 character limit, or the limit on the number of long text fields per query, etc. In other words, we should always try to query exactly the fields we need for optimal performance for our own programs (saving bandwidth, CPU, and memory), but also to be a good neighbor to everyone else.

Also note that virtually every DBA will tell you that you should never use "select * from table" even in other databases, like MySQL, because it will have a similar effect. Salesforce is really just enforcing the best practices that all DBAs and programmers everywhere should use.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha