You need to sign in to do that
Don't have an account?
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).
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
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,
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
Thanks Hitesh
Your solution has worked for me. thanks a lot. I have clicked Kudos for the solution as well :) :)
Best Regards,
Amit
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