You need to sign in to do that
Don't have an account?
Matthias Kimmig
How can I pass a value to the Apex class from the current Visualforce page/Opportunity?
Hey,
this is my first visualforce page.
I have one question concerning Apex class. How can I pass a value to the Apex class from the current Visualforce page/Opportunity? For example, the zip code?
In Germany, the postal code consists of 5 digits. But I want to pass only the first 3 digits to the Apex class. How does it work?
Visualfoce page:
Apex-Class:
This command ":LEFT(currentobject.zip_Code__c,3)" does not work. What is the correct command?
Thanks for your answers.
this is my first visualforce page.
I have one question concerning Apex class. How can I pass a value to the Apex class from the current Visualforce page/Opportunity? For example, the zip code?
In Germany, the postal code consists of 5 digits. But I want to pass only the first 3 digits to the Apex class. How does it work?
Visualfoce page:
<apex:page standardController="Opportunity" extensions="Controller" tabStyle="Opportunity"> <apex:pageBlock title="zip code"> <apex:pageBlockTable value="{!opp}" var="Opportunity" > <apex:column value="{!Opportunity.AccountId}"/> <apex:column value="{!Opportunity.City__c}"/> <apex:column value="{!Opportunity.Zip_Code__c}"/> <apex:column headerValue="Link"> <apex:outputLink value="{!'/'&Opportunity.AccountId}">Link</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Apex-Class:
public class Controller { public List<Opportunity>opp{get; set;} public Controller(ApexPages.StandardController controller){ opp = [SELECT Zip_Code__c, Stadt__c, AccountId FROM Opportunity WHERE Zip_Code__c LIKE :LEFT(currentobject.zip_Code__c,3); } }
This command ":LEFT(currentobject.zip_Code__c,3)" does not work. What is the correct command?
Thanks for your answers.
My name is Shingo Yamazaki.
How about using controller.getRecord() method to get current object?
But I'm not sure whether the function LEFT is available in SOQL.
(Maybe it's not...)
Instead, you can use String.substring function.
All Answers
opp = new List<Opportunity>();
My name is Shingo Yamazaki.
How about using controller.getRecord() method to get current object?
But I'm not sure whether the function LEFT is available in SOQL.
(Maybe it's not...)
Instead, you can use String.substring function.
Use the method Substring define it with the arguments Integer startIndex,Integer endIndex
It returns a new String that begins with the character at the specified startIndex and extends to the character at endIndex.
For example:
'hamburger'.substring(4, 8);
// Returns "urge"
'smiles'.substring(1, 5);
// Returns "mile"
'longer'.substring(0, 3);
// Returns "lon"
Like this get your substring in one variable and pass it to Query.
thanks for your answer.
The new apex-class:
Now, I get an error message in the Opportunity view.
What could be the problem?
thx.
Please try to add one line to Visualforce.
The command "WHERE Zip_Code__c LIKE :zip" doesn't work. The list is empty if I execute the querry.
I have tested some ways but I find no solution. Could you help me?