0

I have a list of open and closed opps from a selectedaccount, this works fine. But if I want to change the picklist fields (RecordType, Stage) should change the dependent field. The fields Stage and Probability standardfields and the values are stored in salesforce.

RecordType(Product) --> Stage --> Probility

But If I run this like in my code below, the dependence doesn't work.

For example: If I change the recordtype to product 3 the field stage should show Stage1 and Stage2 and the dependet field get blank. And If I change the stage the dependent field should adapt.

table

CLASS

Public List <Opportunity> getOppList2() {
OppList1 =  [SELECT Id, Name, RecordTypeId, RecordType.Name, StageName, Amount, CloseDate, Probability, Bewertung_in__c FROM Opportunity WHERE AccountId = :SelectedAccountId AND IsClosed = false ORDER BY CloseDate DESC];
RETURN OppList1;    
}

Public List <Opportunity> getOppListClosed2() {
OppListClosed1 =  [SELECT Id, Name, RecordTypeId, RecordType.Name, StageName, Amount, CloseDate, Probability, Bewertung_in__c FROM Opportunity WHERE AccountId = :SelectedAccountId AND IsClosed = true ORDER BY CloseDate DESC LIMIT 10];
RETURN OppListClosed1;    
}

Public pageReference getOppList() {
getOppList2(); 
getOppListClosed2();

RETURN NULL; 
}    

Public PageReference SaveInlineListChanges() {
UPDATE OppList1;
UPDATE OppListClosed1;


RETURN NULL;
}

Public PageReference CancelInlineListChanges() {
RETURN ApexPages.CurrentPage();
}

VISUALFORCE

<apex:outputpanel id="oppOppList">

<apex:pageblock title="Opportunity List" id="pbOpp" mode="inlineEdit">
<apex:pageBlockButtons location="top">
    <apex:commandButton action="{!SaveInlineListChanges}" value="save" id="saveButton0"/>
    <apex:commandButton action="{!CancelInlineListChanges}" value="cancel" id="cancelButton0"/>
</apex:pageBlockButtons>
<apex:outputtext style="font-size:12pt; font-weight: bold" value="open Opps"/>
<apex:pageblocktable value="{!OppList2}" title="open Opps" var="Opp" columnsWidth="5%,15%,15%,10%,15%,15%,5%,20%">
    <apex:column headervalue="LINK"> <apex:outputLink target="_blank" value="/{!Opp.Id}">Details</apex:outputLink> </apex:column>
    <apex:column headervalue="Name"> <apex:inputfield value="{!Opp.Name}" required="true"/> </apex:column>    
     <apex:column headervalue="Product"> <apex:inputfield value="{!Opp.RecordTypeId}" required="true"/> </apex:column> 
    <apex:column headervalue="Amount"> <apex:inputfield value="{!Opp.Amount}" style="width:90px" required="true"/> </apex:column>
    <apex:column headervalue="Amount in"> <apex:inputfield value="{!Opp.Amount_in__c}" required="true"/> </apex:column>         
    <apex:column headervalue="Stage"> <apex:inputfield value="{!Opp.StageName}" required="true"/> </apex:column>
     <apex:column headervalue="Probility"> <apex:inputfield value="{!Opp.Probability}" style="width:60px" required="true"/> </apex:column> 
    <apex:column headervalue="Close Date"> <apex:inputfield value="{!Opp.CloseDate}" required="true"/> </apex:column>              
</apex:pageblocktable>

<br/>

<apex:outputtext style="font-size:12pt; font-weight: bold" value="closed Opps" />
<apex:pageblocktable value="{!OppListClosed2}" title="geschlossene Verkaufschancen" var="Opp" rendered="{!IF(newOpp=0,true,false)}" columnsWidth="5%,15%,15%,10%,15%,15%,5%,20%">
    <apex:column headervalue="LINK"> <apex:outputLink target="_blank" value="/{!Opp.Id}">Details</apex:outputLink> </apex:column>
    <apex:column headervalue="Name"> <apex:outputtext value="{!Opp.Name}"/> </apex:column>    
    <apex:column headervalue="Product"> <apex:outputtext value="{!Opp.RecordType.Name}"/> </apex:column>                          
    <apex:column headervalue="Amount"> 
        <apex:outputText value="{0, number, #,##0}"> <apex:param value="{!Opp.Amount}"/> </apex:outputText>
    </apex:column>        
    <apex:column headervalue="Amount in"> <apex:outputtext value="{!Opp.Amount_in__c}"/> </apex:column>         
    <apex:column headervalue="Stage"> <apex:inputfield value="{!Opp.StageName}"/> </apex:column>
    <apex:column headervalue="Probability"> <apex:outputtext value="{!Opp.Probability}" style="width:60px"/> </apex:column>
    <apex:column headervalue="Schlussdatum"> 
        <apex:outputText value="{0,date,dd'.'MM'.'yyyy}"> <apex:param value="{!Opp.CloseDate}"/> </apex:outputText>
    </apex:column>
</apex:pageblocktable>

</apex:pageBlock>

</apex:outputpanel>
0

Your controller has no getters or setters to check for dependencies when changes are made to see that they're done according to your table. Picklists are simply strings. Via apex, you can insert any string value you want, including values that aren't in the picklist. Your controller needs to have methods that check for the proper values to use as one value changes and sets the related values accordingly when they occur.

That's going to require you to use a schema call to get all of the field combinations in the chart to use for comparison and to know what to change. Issue you're going to have is how to prioritize what else changes when a user makes changes to fields. You'll need to decide which one is the highest priority, 2nd highest, etc (enforce the dependency), so if a user makes a change that doesn't fit the schema, it won't be allowed.

Edit

I wouldn't be doing you any favors by providing you with a complete solution or code with exactly how to solve your issue. If I did, you wouldn't learn anything and wouldn't be able to troubleshoot problems or know how to solve a similar problem for yourself in the future. Instead, I'm going to provide you with a list of resources of where I think you should begin and what you'll likely want to use.

You're probably going to need to start by reading the Dynamic Apex section of the Apex Code Developer's Guide, particularly the PicklistEntryClass which is what I'd expect you to need to use if you want to make this code self-sustaining. The latter contains methods like this:

Schema.DescribeFieldResult F = Account.Industry.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();

If your picklist values should ever change, you won't need to rewrite your code every time it does if you use this kind of coding.

There's similar code to obtain RecordTypes. You're going to need to construct methods that get the related fields whenever one of these values changes, then tests to see if a related value should also change. If it does, you'll need to decide whether to automatically change to a default value, present a menu to select the new value, or pop-up an alert message telling the user to select one of the acceptable associated values.

How to do that and which options to present is going to be up to you. Obviously, there are many combinations, but only some will be acceptable and you'll need to sort out how to check to see if they will work. That's why in-line editing isn't particularly a good option for this type of complex data.

I hope this helps get you started on your way. Regardless of what you do, I wouldn't recommend hard coding the picklist and record types into your page or controller because they could easily change.

  • Ok, but can you help me a bit more. At the moment I have no idea to solve the problem. – peXeq Jul 29 '15 at 13:42
  • Haven't been able to respond until today. See my edited answer. – crmprogdev Jul 31 '15 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.