You need to sign in to do that
Don't have an account?
NaypersMclgx
To add an Account column in a Oportunnity table (to see who owns the opp)
Hi, I hope somebody can help me.
I need to add an account column in a Oportunnity table, I'm using a pageBlockTable that receive a list (List<Opportunity>), and I'm using a Controller.
I have this in my controller...
// CONTROLLER public Opportunity[] getMyObjectOpportunities() { String sortFullExp = sortExpression + ' ' + sortDirection; List<Opportunity> itemsOpportunities; String sqlFilter = ''; sqlFilter += ' SELECT Name, '; sqlFilter += ' stageName, '; sqlFilter += ' closeDate, '; sqlFilter += ' Id, '; sqlFilter += ' Probability, '; sqlFilter += ' Amount '; sqlFilter += ' FROM Opportunity WHERE CreatedById = \'' + getUserId() + '\''; sqlFilter += ' ORDER BY ' + sortFullExp + ' LIMIT 1000'; itemsOpportunities = DataBase.query(sqlFilter); return itemsOpportunities ; }
Thak you.
Hi,
Add ‘account.name’ field in your query for displaying the account name in page block table.
Like
sqlFilter += ' SELECT Name, ';
sqlFilter += ' stageName, ';
sqlFilter += ' closeDate, ';
sqlFilter += ' Id, ';
sqlFilter += ' Account.name, ';
sqlFilter += ' Probability, ';
sqlFilter += ' Amount ';
sqlFilter += ' FROM Opportunity WHERE CreatedById = \'' + getUserId() + '\'';
sqlFilter += ' ORDER BY ' + sortFullExp + ' LIMIT 1000';
Use the below code snippet as reference:
--- Vf page-------------
<apex:page controller="accountwithopp" >
<apex:pageBlock >
<apex:pageBlockTable value="{!opp}" var="p">
<apex:column >{!p.id}</Apex:column>
<apex:column >{!p.account.name}</Apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
------------- apex controller ------------------
public class accountwithopp {
public list<Opportunity > opp{get;set;}
public accountwithopp ()
{
opp=[select id, account.name from Opportunity limit 1000];
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
Add ‘account.name’ field in your query for displaying the account name in page block table.
Like
sqlFilter += ' SELECT Name, ';
sqlFilter += ' stageName, ';
sqlFilter += ' closeDate, ';
sqlFilter += ' Id, ';
sqlFilter += ' Account.name, ';
sqlFilter += ' Probability, ';
sqlFilter += ' Amount ';
sqlFilter += ' FROM Opportunity WHERE CreatedById = \'' + getUserId() + '\'';
sqlFilter += ' ORDER BY ' + sortFullExp + ' LIMIT 1000';
Use the below code snippet as reference:
--- Vf page-------------
<apex:page controller="accountwithopp" >
<apex:pageBlock >
<apex:pageBlockTable value="{!opp}" var="p">
<apex:column >{!p.id}</Apex:column>
<apex:column >{!p.account.name}</Apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
------------- apex controller ------------------
public class accountwithopp {
public list<Opportunity > opp{get;set;}
public accountwithopp ()
{
opp=[select id, account.name from Opportunity limit 1000];
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Yes perfect!!!, thank you very much...