• Miti dati
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1


I am a beginner to Salesforce development.


By default, from the Partner related list on the Opportunity, you can create OpportunityPartner junction objects between an Opportunity and a Partner Account. We want to modify this page. Unfortunately this object is not very easy to customize.


We have come up with a solution that works for us though.

I am going to create a Visualforce page with standardController 'Opportunity' and with an extension class.

The Visualforce page should be built up to look similar to the current Partner Edit page. 


So we are going to have five rows of partners where you can choose if its primary or not, the AccountToId and the Role. You don't have to fill in information on all rows.


I am not at all done with this yet and many things are not working as I would like them too (the radio buttons for instance). But currently I am stuck with the problem that the getters for the partner variables work but the setters does not. In other words I know that the getPartner methods have been run since I have seen this in the debug logs. The setters are never run though and this becomes obvious and also a problem when I try to insert one of the defined partners in the save method . I get an error that the field 'AccountToId' is a required field and should have a value:



Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AccountToId]: [AccountToId]



Furthermore as you can see I have chosen to use the Partner object since I am not allowed to create OpportunityPartner objects. But when a Partner object gets created an OpportunityPartner object also does so that shouldn't be a problem.


VisualForce page:


<apex:page title="Partners: {!Opportunity.Name}" standardController="Opportunity" extensions="PartnerEditExt" showheader="true" sidebar="true" id="thePage"> <apex:sectionHeader title="Partners" subtitle="{!Opportunity.Name}" id="partnerEditSectionId" help="javascript:openPopupFocusEscapePounds(%27/help/doc/user_ed.jsp?loc=help&target=partners_edit.htm&section=Partners&showSplash=true%27, %27Help%27, 700, 600, %27width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no%27, false, false);"></apex:sectionHeader> <apex:pageMessages /> <apex:form id="theForm"> <apex:pageBlock title="Partners Edit"> <apex:pageBlockSection columns="3"> <!-- Headings --> <apex:outputText value="Primary" style="font-weight:bold" /> <apex:outputText value="Partner" style="font-weight:bold" /> <apex:outputText value="Role" style="font-weight:bold" /> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner0.isPrimary}" id="fromPartnerPrimary0"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="No Partner" id="noPartnerAccount"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem /> <!-- Partner 1 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.isPrimary}" id="fromPartnerPrimary1" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.AccountToId}" id="fromPartner1" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.Role}" id="fromPartnerRole1" /> </apex:pageBlockSectionItem> <!-- Partner 2 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.isPrimary}" id="fromPartnerPrimary2"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.AccountToId}" id="fromPartner2"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.Role}" id="fromPartnerRole2"/> </apex:pageBlockSectionItem> <!-- Partner 3 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.isPrimary}" id="fromPartnerPrimary3"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.AccountToId}" id="fromPartner3"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.Role}" id="fromPartnerRole3"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!save}" value="Save" immediate="true" /> <apex:commandButton action="{!Cancel}" value="Cancel" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>


The Apex extension class:


public with sharing class PartnerEditExt { final Opportunity opp; Partner partner0 = null; Partner partner1 = null; Partner partner2 = null; Partner partner3 = null; ID oppId; ID accId; ID noPartnerAccId = [select id from Account where Name = 'no partner'].Id; /* Constructor */ public PartnerEditExt(ApexPages.StandardController controller) { opp = (Opportunity)controller.getRecord(); oppId = controller.getRecord().Id; accId = [select AccountId from Opportunity where Id = :oppId].AccountId; partner0 = new Partner(OpportunityId=oppId); partner1 = new Partner(OpportunityId=oppId); partner2 = new Partner(OpportunityId=oppId); partner3 = new Partner(OpportunityId=oppId); } /* Save action Insert the specified partners */ public void save() { // Currently no intelligent logic here // I just want to test that partner1 can be inserted insert partner1; } /* Cancel action Redirect user back to opportunity */ public PageReference cancel() { String curr = '/'+ApexPages.currentPage().getParameters().get('id'); PageReference pageref = new Pagereference(curr); return pageref; } /* Getters and Setters for the partner variables */ public Partner getPartner0() { return partner0; } public void setPartner0(Partner p) { partner0 = p; } public Partner getPartner1() { return partner1; } public void setPartner1(Partner p) { partner1 = p; } public Partner getPartner2() { return partner2; } public void setPartner2(Partner p) { partner2 = p; } public Partner getPartner3() { return partner3; } public void setPartner3(Partner p) { partner3 = p; } }


 Some of you might wonder why we didn't choose to use a custom object instead. We though of this but made the assumption that this work would take less time and also be less risky.


What have I done wrong?

I think I might miss some basic understanding here. A solution to my problem with a good explanation would be very welcome!



Thanks / Niklas