Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Hi All,

I am skeptical if it is possible. Account has many cases. Is there any way if under a case a article is attached, can we show that article on account as a related list. For example Account A has Case 1,2 and 3 and if Case 1 has article as a,b and case 2 has article as x,y. Then account show related list of article as a,b,x and y. Is it possible as it doesn't seem there is a relationship between  account and article? Let me know 

Thanks

A
3 answers
  1. Mar 30, 2015, 7:06 PM
    Hi Adda,

    please refer the below code : 

    public class Sample { 

        public Id Aid {get;set;}

        public list<article__c> lstArticles{get;set;}

        public set<Id> setCaseIDs = new set<Id>();

        

        public Sample(ApexPages.StandardController controller) {

            Account acc = new Account();

            Aid = controller.getId();

            lstArticles = new list<articles__C>();

            

            for(Case objCase : [Select Id from Case where AccountId = : Aid])

            {

                SetCaseIds.add(objCase.Id);

            }

            

            for(Article__c objArticle : [Select Id, Name from Article__c where CaseId IN SetCaseIds])

            {

                lstArticles.add(objArticle);

            }

        

        }     

        

        

    }

    VF Page

    <apex:page standardController="Account" extension="Sample ">

        <table border="0" >

            <apex:repeat var="art" value="{!lstArticles}">

            <tr>

                <td>{!art.Name}</td>

                            

            </tr>

            </apex:repeat> 

        </table>

    </apex:page>

    You can query the data in your controller and then you can show them in Vf page as I shown above..

    Please correct synatx erros and check with above code that will solve your issue..

    P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

    Thanks,

    Sandeep

    Salesforce Certified Developer 

Loading
0/9000