You need to sign in to do that
Don't have an account?
harsha vardhan vasa 9
junction object fields not displaying on vf page
hi guys,
i have implemented vf to get the userterritory detatils for the entered username in search box.i am able to get the results from the soql query but not able to display on vf screen,
PFB code and let know where i went wrong.
VF Page:
<apex:page controller="Apexcontroller" >
<apex:form >
<apex:pageBlock >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockSection >
<apex:inputText value="{!searchstring}" label=" enter username here" />
<apex:commandButton value="Search" action="{!search}" reRender="accpg,showmsg" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!usrter}" var="a" id="accpg" rendered="{!usrter.size!= 0}">
<!-- <apex:column value="{!a.id}" /> -->
<apex:column headerValue="user">
<apex:inputfield required="{false}" value="{!a.userid}" />
</apex:column>
<apex:column headerValue="Territory">
<apex:inputfield required="{false}" value="{!a.territoryid}" />
</apex:column>
<!-- <apex:column value="{!a.territoryid}" /> -->
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class Apexcontroller {
public string searchstring{get;set;}
public list<userterritory> usrter{get;set;}
public list<user> usrlist = new list<user>();
public Apexcontroller(){
usrter =new list<userterritory>();
}
public void search(){
system.debug('value of searchstring entered is'+searchstring);
user[] usr =[select id from user where username =:searchstring];
for(user u:usr){
usrter=[select id,userid,territoryid,isactive from userterritory where userid =:u.id];
system.debug('userterritory list is'+usrter);
if(usrter.size() ==0){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'No matching territories found for the entered username'));
}
}
}
public void save(){
}
}
i have implemented vf to get the userterritory detatils for the entered username in search box.i am able to get the results from the soql query but not able to display on vf screen,
PFB code and let know where i went wrong.
VF Page:
<apex:page controller="Apexcontroller" >
<apex:form >
<apex:pageBlock >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockSection >
<apex:inputText value="{!searchstring}" label=" enter username here" />
<apex:commandButton value="Search" action="{!search}" reRender="accpg,showmsg" />
</apex:pageBlockSection>
<apex:pageBlockTable value="{!usrter}" var="a" id="accpg" rendered="{!usrter.size!= 0}">
<!-- <apex:column value="{!a.id}" /> -->
<apex:column headerValue="user">
<apex:inputfield required="{false}" value="{!a.userid}" />
</apex:column>
<apex:column headerValue="Territory">
<apex:inputfield required="{false}" value="{!a.territoryid}" />
</apex:column>
<!-- <apex:column value="{!a.territoryid}" /> -->
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class Apexcontroller {
public string searchstring{get;set;}
public list<userterritory> usrter{get;set;}
public list<user> usrlist = new list<user>();
public Apexcontroller(){
usrter =new list<userterritory>();
}
public void search(){
system.debug('value of searchstring entered is'+searchstring);
user[] usr =[select id from user where username =:searchstring];
for(user u:usr){
usrter=[select id,userid,territoryid,isactive from userterritory where userid =:u.id];
system.debug('userterritory list is'+usrter);
if(usrter.size() ==0){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'No matching territories found for the entered username'));
}
}
}
public void save(){
}
}
Greetings to you!
- I can help you but I need your object name and API name and their respective fields name and API names because 'userterritory' is a custom object and custom object appends '__c' so it should be 'userterritory__c' and its fields also appends __c.
- You are doing SOQL query within the for loop which can hit the governor limit and throw an error. Change your controller class to the below class : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
thanks for ur time and effort.
userterritory is standard junction object between user and territory objects in territory management.
Regards,
Harsha
8446546754.