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
sfdcIssfdcIs 

converting sObject to string

I am trying to convert this contact sObject to a string to grab the first 5 characters of the zip and compare but keep getting an error of "method does not exist or incorrect signature. any ideas?

 

String bpc= String.valueOf(c.MailingPostalCode);

 

if(bpc.left(5)>= cList.get(i).zip)

{

 // more processing

}

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

to convert a string of type number to Integer.. you should use Integer.valueOf

 

String bpc= String.valueOf(c.MailingPostalCode);

if(integer.valueOf(bpc.substring(0,5))>= cList.get(i).zip)
{
// more processing
}

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

String method left is available in winter 13... I think the instance that you are working has not been upgraded to new version yet.

 

Check this link for winter 13 upgrade on your instance.

 

http://trust.salesforce.com/trust/maintenance/

 

 

sfdcIssfdcIs

Ok thank you so there is no way we can manipulate this until the new release comes out?

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

you can use other methods...

 

use bpc.substring(0,5) instead of bpc.left(5).

sfdcIssfdcIs

ok  i am getting very close now . The code compiled successfully.  however, I realzied that the number comparison will not work since it's a string literal.  need to grab the first 5 characters then compare it as a number with 5 characters

 

String bpc= String.valueOf(c.MailingPostalCode);

if(bpc.substring(0,5)>= cList.get(i).zip)
{
// more processing
}

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

to convert a string of type number to Integer.. you should use Integer.valueOf

 

String bpc= String.valueOf(c.MailingPostalCode);

if(integer.valueOf(bpc.substring(0,5))>= cList.get(i).zip)
{
// more processing
}

This was selected as the best answer