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
Amit_Amit_ 

Convert sObject to Integer

Hi everyone,

I have small doubt, and I dont know how to solve it . Please help me to solve my issue. I'm new to salesforce

list<sObject> slist = new list<sObject>();

sList =[select TotalSize__c from sObject where id in : 90908908];

TotalSize__c is a Integer field.

 

How will I compare the value of TotalSize__c  that I got in sList to theTotalSize__c Integer data type as sList returns sObject data type.

I am trying to comapre using if conditon (if sList.get[0] == 4). it is throwing error as :

Compile Error: Initial term of field expression must be a concrete SObject: LIST<sObject> for the line number : (if sList.get[0] == 4).

hitesh90hitesh90

Hi Amit,

 

you have to write if condition like this.

(if sList.size() == 4).

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

Amit_Amit_

Hi Hitesh,

 

if I write sList.size() this will give the size of the list. I dont want that.

what my requiremnt is there is custom filed called TotalSize__c and value of this filed is 4. Its a integer field.

now  I will have to comapre my sList with the integer value. to check the value that I'm getting from SOQL is eauls to 4 of not .

as sList is reurning sObject data type, I'm finding it hard to comapre it with integer.

 

Thanks & Regards,

hitesh90hitesh90

Hi Amit,

 

do you want to compare TotalSize__c field to 4 right?

then you can use if condition like this.

(if sList[0].TotalSize__c == 4)

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

Amit_Amit_

Thanks Hitesh

 

Your solution has worked for me. thanks a lot. I have clicked Kudos for the solution as well  :) :)

 

 

Best Regards,

Amit

anishaanisha

Hi Amit.

 

if it is for one record.  you can use like.

 

Integer  str = Integer.Valueof ([Select Active_Cardholders__c from Account where

 

id='001Q000000cjOfd'].Active_Cardholders__c);

 

here Active_Cardholders__c is number field.

 

If it is for bulk then.

 

// this is array of integer, but also you can access list methods

 

List<integer> str = new integer[]{};

 

for(Account d: [Select Active_Cardholders__c from Account where Active_Cardholders__c!= Null limit 2 ])
{
 Str.add(integer.valueOf(d.Active_Cardholders__c));   
}

 

 

please let me know if you have any question, if it is right mark it right one. so that it will be benefical for others

 

Thanks

Nikhil