function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Laytro80Laytro80 

Apex Trigger I think

Hi,

 

I have an object called meeting note and a child object called attendee.

 

When you create a meeting you can add as many attendees as you want.

 

What I would like to happen is when you add an attendee and hit save you are returned not to the attendee record but to the linked meeting note.

 

Thanks

 

Ross

Best Answer chosen by Admin (Salesforce Developers) 
JoeyDJoeyD

 

public class atendeeExt {

    Atendee__c atendee;

    public atendeeExt(ApexPages.StandardController ctlr){
        //this line might be unnecessary
		this.atendee = (Atendee__c)ctlr.getRecord();
    }
    
    
    public Atendee__c getAtendee(){
        if(atendee == null) atendee = new Atendee__c();
        return atendee;
    }
    

    public PageReference Save(){
		try{
			insert atendee;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        } 
        PageReference pr = new PageReference('/'+atendee.Meeting_Notes__c);
        pr.setRedirect(True);
			return pr;
	}
}


Make sure the master-detail field (I'm assuming Meeting Notes) is somewhere on the VF page:

<apex:page standardController="Atendee__c" extensions="atendeeExt">
	<apex:form>
		<apex:outputField value="{!Atendee__c.Meeting_Notes__c}" rendered="false"/>
	<!-- etc etc -->

 

Let me know if this works. I'm pretty new to Apex too :)

 

All Answers

jhenningjhenning

Ross,

 

You don't want a trigger. In this case you could build a custom visualforce page for the attendee 'add' function. The page would need a custom controller extension that can redirect the user to the parent object page after the save.

Laytro80Laytro80

Thanks John,

 

Appreciate the pointer.

 

Very new to APEX development, can handle the visualforce page ui.

 

The controller is a new thing for me, will have a look at the tutorials.

 

Any pointers on the controller code required to do this?

 

Cheers


R

JoeyDJoeyD

 

public class atendeeExt {

    Atendee__c atendee;

    public atendeeExt(ApexPages.StandardController ctlr){
        //this line might be unnecessary
		this.atendee = (Atendee__c)ctlr.getRecord();
    }
    
    
    public Atendee__c getAtendee(){
        if(atendee == null) atendee = new Atendee__c();
        return atendee;
    }
    

    public PageReference Save(){
		try{
			insert atendee;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        } 
        PageReference pr = new PageReference('/'+atendee.Meeting_Notes__c);
        pr.setRedirect(True);
			return pr;
	}
}


Make sure the master-detail field (I'm assuming Meeting Notes) is somewhere on the VF page:

<apex:page standardController="Atendee__c" extensions="atendeeExt">
	<apex:form>
		<apex:outputField value="{!Atendee__c.Meeting_Notes__c}" rendered="false"/>
	<!-- etc etc -->

 

Let me know if this works. I'm pretty new to Apex too :)

 

This was selected as the best answer
Laytro80Laytro80

Big thanks for this.  I am just refreshing the sandbox so will have a go with the code tonight / first thing.   Many thanks.

 

Ross

Laytro80Laytro80

Thanks John &