• Neil Wingate 7
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Here is VF Component..
 
<apex:page standardcontroller="Account" extensions="accountSatController">
<apex:form >
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <title>jQuery UI Accordion - Collapse content</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#accordion" ).accordion({
      collapsible: true,active: false
    });
  } );
  </script>
</head>
<body>
<div id="accordion">
<apex:repeat value="{!satellite}" var="sat">
<h3><apex:outputLink value="/{!sat.id}" target="_parent">Right Click/Open To View -- {!sat.name}</apex:outputlink></h3>
<div><apex:outputLink value="/{!sat.id}" target="_parent">View Record</apex:outputlink><br/>
      {!sat.BillingStreet}, {!sat.BillingCity}, {!sat.BillingState}, {!sat.BillingPostalCode}, Phone: {!sat.Phone}, Fax: {!sat.Fax}<br/><br/>
</div>
</apex:repeat>
</div>
</body>
</html>
</apex:form>
</apex:page>

Here is Controller...
 
public with sharing class accountSatController {
    
    public accountSatController () {
    }
    
    public accountSatController(ApexPages.StandardController controller) {
    	ParentAccount = (Account)controller.getRecord(); 
    	satellite = [SELECT Id, Name, Phone, Fax,  BillingCity, BillingStreet, BillingState, BillingPostalCode, ParentId, Parent.Name FROM Account WHERE ParentId = :ParentAccount.Id OR Id = :ParentAccount.Id ORDER BY ParentId asc];
    }
    
    public List<Account> satellite{get;set;}
    public Account ParentAccount;
}

Here is my lame test class... bit of a mess, creating four accounts, with one being the Parent of all three... and then calling the VF component to display on an account page (the page of any of the four previously created)
 
@isTest
public class accountSatContr_Test {

    public static testMethod void myUnitTest() {
    	
		//Instantiate a new controller with all parameters in the page
        PageReference pageRef = Page.AccountSatellites;
        Test.setCurrentPage(pageRef);
        
        List<Account> satellite = new List<Account>();
    	
        Id BusinessRTId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Business').getRecordTypeId();
    
        List<Account> accountTree = new List<Account>();
        
        account a = new account (
        name = 'TestBusinessNamea',
        RecordTypeId = BusinessRTId,
        Phone = '4525251254'
        );
        insert a;
        
        account b = new account (
        name = 'TestBusinessNameb',
        RecordTypeId = BusinessRTId,
        Phone = '4525251254',
        ParentId = a.id
        );
        accountTree.add(b);
        account c = new account (
        name = 'TestBusinessNamec',
        RecordTypeId = BusinessRTId,
        Phone = '4525251254',
        ParentId = a.id
        );
        accountTree.add(c);
        account d = new account (
        name = 'TestBusinessNamed',
        RecordTypeId = BusinessRTId,
        Phone = '4525251254',
        ParentId = a.id
        );
        accountTree.add(d);
        
        insert accountTree;
		
        accountSatController controller = new accountSatController();
        controller.ParentAccount = a;
        //controller.satellite;// = [SELECT Id, Name, Phone, Fax,  BillingCity, BillingStreet, BillingState, BillingPostalCode, ParentId, Parent.Name FROM Account
                   //WHERE ParentId = :ParentAccount.Id OR Id = :ParentAccount.Id ORDER BY ParentId asc];
        System.debug(satellite.size());
		//System.assert(satellite.size()==4);
		
        //page.setRedirect(true);
        //return pageRef;
        
           	
        // TO DO: implement unit test
        
    }
}



 

Hey Guys,

i am looking for a "best practice" solution, to create a conditionally url button. The button should be placed on the standard page layout.
Related to a value of the object, the button button should redirect the user to a page.

For example, if the status is x, redirect to a new task.
if the status is y, redirect to the homepage.
if the status is z, redirect to an external page.

Unfortunately, a javascript button is not a soultion for lightning.

I have created a controller and a methode to create a conditionally PageReference for each case. I dont think that this solution is best practice. Moreover, i used simply urls like
1new PageReference('https://...............+lead.id');
what is definitely not best practise.  So my button opens the page which is fireing the action methode automatically.

Conclusion, i am looking for : 
- a solution for lightning and classic
- a button placed on the standard page layout
- the button should redirect to different pages related to a value of the object
- a more best practice solution than mine 

I appreciate your help ! 

Cheers, 
Marry