I am working on an org with Person Accounts enabled, but I think that my problem applies to regular non-person Accounts as well.

I am tasked with writing a trigger to cross-populate spouse information for Accounts that have an AccountPartner object where role=spouse.

This works fine for when the Account object is update/inserted/deleted/undeleted. The problem is that creating or deleting a partner relationship does not cause the trigger on the Account object to fire. So you can create John and Jane Doe, and when you create each of them the trigger will fire on insert, but they are not partners yet and no information will be cross-populated. Now you go to the record you just created and add a new partner relationship and set the type to spouse. This creates the AccountPartner object but does not update the Account record and therefore the trigger is not fired.

My solution was to create a trigger on the AccountPartner object, except I get the error:

sObject type does not allow triggers: AccountPartner

The same is true for the Partner object

sObject type does not allow triggers: Partner

So I'm stuck here. How do I cause my trigger to fire when two accounts are linked via a partner relationship? Or how do I populate a custom field on each Account with a value from the partner account?

  • Have you tried creating a cross-object workflow that would fire on insert? I've never worked with AccountPartner object, it might be the case it doesn't support workflows either. Or maybe check if you can make a trigger on Partner object instead odf AccountPartner: salesforce.com/us/developer/docs/api/Content/…
    – eyescream
    Oct 28, 2012 at 20:48
  • The Partner object also does not allow triggers. I haven't tried a cross-object workflow. I'm new to Salesforce so I don't actually know how to create a workflow, but I will look into it and let you know if it solves me problem. Thanks for the lead.
    – Aaron P.
    Oct 28, 2012 at 20:58
  • It looks like the AccountPartner and Partner objects do not support workflows either. Any other ideas?
    – Aaron P.
    Oct 28, 2012 at 21:13
  • Maybe let's hit it from other side - what is the result you're after? If it's "count of spouses" or sth like that - SF can calculate it for you without any coding (search for "rollup summary field"). If it's something more complex - does it have to be realtime? Would a scheduled job that runs say every hour and searches for recently added AccountPartner objects meet your requirements?
    – eyescream
    Oct 28, 2012 at 21:50
  • @eyescream We have created some custom fields for the spouse information - boolean Spouse_Relationship_Exists__c and string Spouse_FirstName__c, Spouse_LastName__c. There's a few more along those lines. Then those fields are used for generating a mailing address using some formula fields. I will have to check with the client if they must be real-time. Ideally I will find a way to make them real-time but if I am unable to do so I can probably negotiate it.
    – Aaron P.
    Oct 28, 2012 at 22:03

1 Answer 1


Much like AccountContactRole and OpportunityContactRole and other junction objects, it would appear that AccountPartners don't support workflow or triggers either.

I was faced with the same problem on ACRs and OCRs and the couple of solutions possible are :

Override the Partner Related List with a custom VisualForce section, which means you can control all of the users Interaction with the object and trap the event to perform a phantom update on the Account to invoke your trigger, which can process the event as usual. (you can't explicitly insert an AccountPartner, you will need to operate on the Partner object which creates an AccountPartner behind the scenes) Reference : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_partner.htm

Use a custom object to model the AccountPartner relationship, which lets you write triggers and workflows and work as usual. This is the lesser preferable option in my head coz it would mean you miss out on the standard Partner functionality that comes out of the box with Salesforce.

Here's a first cut of what you could use

Controller Class:

public with sharing class PartnerExtension{

 public PartnerExtension(ApexPages.StandardController stdController) {
    this.acct = (Account)stdController.getRecord();

    this.pageMode = 'Detail';

    accPartner = [Select AccountToId, AccountFromId, Role FROM Partner WHERE AccountFromId = :acct.Id];

public Account acct;
public Partner[] accPartner { get; set; }
public String pageMode { get; set; }

public PageReference setEditMode(){
    this.pageMode = 'Edit';
    accPartner =  this.accPartner = new Partner[]{ new Partner(),new Partner(),new Partner(),new Partner(),new Partner()};

    return null;


public PageReference savePartner(){
    List<Partner> partnersToIns = new List<Partner>{};
    List<Account> acctsToUpdt = new List<Account>{};

    for(Partner accP : accPartner){
    if(accP.AccountToId  != null && 
             accP.Role != null){
        accP.AccountFromId = acct.Id;

        if( accP.Role == 'Spouse')
            acctsToUpdt.add(new Account(Id=accp.AccountFromId));
        insert accPartner;

        update acctsToUpdt;

        pageMode = 'Detail';

    accPartner = [Select AccountToId, AccountFromId, Role FROM Partner WHERE AccountFromId = :acct.Id];
    return null;


Visualforce Page :

<apex:page standardController="Account" extensions="PartnerExtension" >

<apex:pageBlock mode="{!pageMode}">

<apex:commandButton value="Save" action="{!savePartner}" rendered="{!pageMode=='Edit'}"/>
<apex:commandButton value="New" action="{!setEditMode}"/>
<apex:commandButton value="Cancel" action="{!Cancel}" rendered="{!pageMode=='Edit'}" />


<apex:pageBlockTable value="{!accPartner}" var="accP">

<apex:column  headerValue="Action" rendered="{!pageMode=='Detail'}">
<a href="/setup/own/deleteredirect.jsp?delID={!accP.Id}&retURL=%2F{!Account.Id}">Del</a>

<apex:column value="{!accP.AccountToId}" rendered="{!pageMode=='Detail'}"/>
<apex:column value="{!accP.Role}" rendered="{!pageMode=='Detail'}"/>

<apex:column headerValue="Partner" rendered="{!pageMode=='Edit'}">
<apex:inputField value="{!accP.AccountToId}" />
<apex:column headerValue="Role" rendered="{!pageMode=='Edit'}">
<apex:inputField value="{!accP.Role}" />


<apex:outputPanel rendered="{!pageMode=='Detail'}">
<a href="/001?rlid=RelatedPartnerList&amp;id={!Account.Id}" target="_BLANK">Go to list(<apex:outputText value="{!accPartner.size}" />)&nbsp;»</a>



  • Thanks for the good ideas. How would I go about overriding the partner related list with a custom VisualForce section? I have written a few VisualForce pages, but I have no idea how to do that. Does it involve editing page layouts? I have not yet done anything with page layouts.
    – Aaron P.
    Oct 28, 2012 at 21:37
  • You would need to create a VF Page with an AccountExtension controller, where the Save method in addition to saving the Partner record, also updates the From or To Account, so that your trigger is invoked. Then edit the Account Page Layout to get rid of the standard Partner Related List, and drop your custom VF Page as a section instead. Oct 28, 2012 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .