You need to sign in to do that
Don't have an account?
SalesforceLearner
I want to display Accounts & its Related Opportunities of a currently login Comunity User on VF page
My Controller :
public class AccountOpportunity {
public String userid{get;set;}
public AccountOpportunity (){
userid = Userinfo.getUserId();
fetchData();
}
public void fetchData(){
List<Opportunity> op = [Select name,Id,AccountId,Amount from Opportunity ];
//Parent Id set
Set<id> parentIdSet = new Set<id>();
//Create parent Id set
for(Opportunity OppRec :op){
parentIdSet.add(OppRec.AccountId);
}
//Fetch all associated parents
List<Account> allAssocaiatedAccounts = [Select name,id,AnnualRevenue,Industry from Account where Id IN : parentIdSet ];
wrapperList = new list<myWrapperClass>();
//For loop to set data
for(Opportunity childRec : allOpps){
//myWrapperClass wrapRec;
for(Account parentRec :allAssocaiatedAccounts){
if(parentRec.Id == childRec.AccountId){
myWrapperClass wrapRec = new myWrapperClass();
wrapRec.acc = parentRec;
wrapRec.opp = childRec;
wrapperList.add(wrapRec);
}
}
//Adding Opportunities without account
if(childRec.AccountId == null){
myWrapperClass wrapRec = new myWrapperClass();
//wrapRec.acc = null;
wrapRec.opp = childRec;
wrapperList.add(wrapRec);
}
}
}
public List<myWrapperClass> wrapperList {get; set;}
public class myWrapperClass{
public Account acc{get;set;}
public Opportunity opp{get;set;}
public Boolean selected {get; set;}
public myWrapperClass() {
selected = false;
}
}
}
public class AccountOpportunity {
public String userid{get;set;}
public AccountOpportunity (){
userid = Userinfo.getUserId();
fetchData();
}
public void fetchData(){
List<Opportunity> op = [Select name,Id,AccountId,Amount from Opportunity ];
//Parent Id set
Set<id> parentIdSet = new Set<id>();
//Create parent Id set
for(Opportunity OppRec :op){
parentIdSet.add(OppRec.AccountId);
}
//Fetch all associated parents
List<Account> allAssocaiatedAccounts = [Select name,id,AnnualRevenue,Industry from Account where Id IN : parentIdSet ];
wrapperList = new list<myWrapperClass>();
//For loop to set data
for(Opportunity childRec : allOpps){
//myWrapperClass wrapRec;
for(Account parentRec :allAssocaiatedAccounts){
if(parentRec.Id == childRec.AccountId){
myWrapperClass wrapRec = new myWrapperClass();
wrapRec.acc = parentRec;
wrapRec.opp = childRec;
wrapperList.add(wrapRec);
}
}
//Adding Opportunities without account
if(childRec.AccountId == null){
myWrapperClass wrapRec = new myWrapperClass();
//wrapRec.acc = null;
wrapRec.opp = childRec;
wrapperList.add(wrapRec);
}
}
}
public List<myWrapperClass> wrapperList {get; set;}
public class myWrapperClass{
public Account acc{get;set;}
public Opportunity opp{get;set;}
public Boolean selected {get; set;}
public myWrapperClass() {
selected = false;
}
}
}
Hope Below Code Will Help :-
--
Thanks,
Swayam
@Salesforceguy