+ Start a Discussion
SalesforceLearnerNewbieSalesforceLearnerNewbie 

how to pass the value from apex:repeat to controller

I have a List of IDs "a" = ["12dfd1", "123hte32", "dslkf3134"]
and when I use in VF page.
I do not know how to pass this var = "t" within the repeat apex command back to controller. I want it to pass the value from 12dfd1, 123hte32 to dslkf3134 one by one.
I created public String get_id {get;set;} in apex controller but how can I store the value from the apex:repeat after it loop each value. I need the value to be loop one by one and printed on VF page and then these value each will send back to controller based on the "var" if possible
GovindarajGovindaraj
Can you try something like below,
 
<apex:repeat value="{!lstNumbers}" var="num">
    <apex:commandLink value="{!num}"    action="{!nextPage}" rerender='frm,projtable">
       <apex:param     name="selectedPage"      value="{!num}"     assignTo="{!selectedPage}"/>
    </apex:commandlink>
</apex:repeat>

Thanks,
Govindaraj.S
SalesforceLearnerNewbieSalesforceLearnerNewbie
Can I know why I should create commandLink please?
 
SalesforceLearnerNewbieSalesforceLearnerNewbie
Its not working, no value is being assignTo my new variable in apex controller even after using this method. 
Raj VakatiRaj Vakati
Refer this code
 
public with sharing class Detailoutputlink1 {
public String rId{get;set;}
public PageReference showDetail() {
pagereference ref = new pagereference('https://ap1.salesforce.com/'+rId);
ref.setredirect(true);
return ref;
}
List<DataLoadTest__c> lstdlt = new List<DataLoadTest__c>();
public List<DataLoadTest__c> getRecords() {
lstdlt=[select Id,name from DataLoadTest__c];
return lstdlt;
}
}
 
<apex:page sidebar="false" controller="Detailoutputlink1">

<apex:form >
<apex:repeat value="{!records}" var="r">
<apex:commandLink value="{!r.Name}" action="{!showDetail}">
<apex:param name="rId" value="{!r.Id}" assignTo="{!rId}"/>
</apex:commandLink>
</apex:repeat>
</apex:form>
</apex:page>

 
SalesforceLearnerNewbieSalesforceLearnerNewbie
May I know what is this for? 

List<DataLoadTest__c> lstdlt = new List<DataLoadTest__c>(); public List<DataLoadTest__c> getRecords() { lstdlt=[select Id,name from DataLoadTest__c]; return lstdlt;
Raj VakatiRaj Vakati
Its Used to Query the list of records to pass to repeated ..
SalesforceLearnerNewbieSalesforceLearnerNewbie

I cant understand from the code you share, could you help me to check my code instead??

 

after receiving the information from an external API:

such as 

{data=({id=c89278c0-4e21-4468-b85b-c18ba4252e87, valid=false, word=I try to get something, task=()}, {id=304264d2-9c15-40c7-bce5-e1aa605edfa8, valid=true, word=I trying to use salesfroce apex, task=({id=d567f0b8-3f14-42a3-863b-b9fd868b3976, info={total=no value, location=dunno、}, task=Will send email})}

Then my controller will be like this :

public with sharing class calloutViewer_Controller {
    public void get_words()
    {
        checking = s_id; 
        httpResponse res = APIExchange.get_words('GET', checking);
        responseBody = res.getBody();
        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
        List<Object> candidates = (List<Object>) results.get('data');
        for (Object candidate: candidates) {
            Map<String, Object> candidatee = (Map<String, Object>)candidate;
            ss_id = (String)candidatee.get('id');
            task = (String)candidatee.get('task');
            
        }   
    }

My APIEchange file is:

    public static httpResponse get_words(String httpMethod, String endpoint)
    {
           httpRequest req = new httpRequest();
        req.setMethod('GET');
        req.setEndpoint('https://ap1.salesforce.com/' + endpoint);
           httpResponse res = new http().send(req);
           return res;
    }


My VF page is below:

<apex:repeat value="{!listA}" var="t" >
                                        <apex:param name="s_id" value="{!t}" assignTo="{!s_id}" />
                                        <apex:pageBlockTable value="{!word}" var="var">
                                        <apex:column headerValue="Word {!task_index + 1    }">
                                            {!t}<br />
                                        </apex:column>
                                    </apex:pageBlockTable>

SalesforceLearnerNewbieSalesforceLearnerNewbie

My "listA" actually is in the form like this [[I trying to use salesfroce apex],[xxxxxxxxxx]]. My word is actually gotten from this.

Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
        List<Object> candidates = (List<Object>) results.get('data');
        listA = new List<String>();
        for (Object candidate: candidates) {
            Map<String, Object> candidatee = (Map<String, Object>)candidate;
            Boolean valid= (Boolean)candidate.get('valid');
            if(valid== True){            
                word= (String)candidatee.get('word');
                listA.add(word);

 

SalesforceLearnerNewbieSalesforceLearnerNewbie




Can anyone assist me in this please, its urgent.