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
shephalishephali 

getting value

hello friends,
This is my controller code:
TableData=[select Code__c from verify__c where ID__c= :s];
 str=String.valueof(TableData);
str contains following value.
ID__c:{Code__c=841095, Id=a012800000703J9AAI}
i want to get only '841095'
how to get this???
Best Answer chosen by shephali
Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use the below code, you can modifiy it according to your need  :

public String str {get;set;} 
public String inputValue{get;set;} 
public PageReference save()
    { 
       if(str.contains(inputValue))
       {
         PageReference pr=new PageReference('/apex/page');
         return pr;
       }
    return null;
    }

Thanks,
Vishal

All Answers

Vishal_GuptaVishal_Gupta
Hi Shephali,

Its better if you can use the TableData directly to fetch Code__c value, please see below code :

I am assuming that your query returning a single row.

public String code = '' ;
List<verify__c > TableData = [select Code__c from verify__c where ID__c= :s];
if(TableData.size()>0)
{
     code = TableData[0].Code__c;
}

If your query return more than 1 row, you can iterarate TableData and implement you logic like this :

List<verify__c > TableData = [select Code__c from verify__c where ID__c= :s];
if(TableData.size()>0)
{
    for(verify__c var: TableData)
    {
          // implement your logic here
    }
}

Please let me know if I can help you more.

Thanks,
Vishal

 
shephalishephali
Thanks Vishal for your regular and quick responses.I appreciate.
Yes it worked.
shephalishephali
Hi Vishal;
     I need to compare str and inputValue on button click and have to return to next vfpage but getting error on that as
$ no viable alternative at character '' $
how to resolve this???
Note:I also tried this using set method.
public String getstr()
   {      
     return str;
   }
    public String getinputValue()
    {         
      return inputValue;
     }
public PageReference save()

    String st= getinputValue();
     String s1=getstr();
    Boolean r = st.contains(s1);
    if(r)
   {
     PageReference pr=new PageReference('/apex/page');
    return pr;
   }
return null;
}
 
Vishal_GuptaVishal_Gupta
Hi Shephali,

Can you please provide your VF page code.

Thanks,
Vishal
shephalishephali
Hey Vishal,
here is my VF page code.I need to compare this 'str' with 'inputValue' on save button click.
<apex:page controller="c1">Your Code::{!str}
         <apex:form >   
        <apex:inputText value="{!inputValue}" id="theTextInput" /><br/>             
        <p>  <apex:commandButton action="{!save}" value="Register Agent mobile"/></p>
        </apex:form>               
</apex:page>
 
Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use the below code, you can modifiy it according to your need  :

public String str {get;set;} 
public String inputValue{get;set;} 
public PageReference save()
    { 
       if(str.contains(inputValue))
       {
         PageReference pr=new PageReference('/apex/page');
         return pr;
       }
    return null;
    }

Thanks,
Vishal
This was selected as the best answer
Vishal_GuptaVishal_Gupta
Hi Shephali,

Is it possible for you to share your org with me, my email id is vishal.er.gupta@gmail.com

Thanks,
Vishal
shephalishephali
Thanks Vishal..!!!
Its working now.