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
rwalrath144rwalrath144 

HELP - At a complete lose and really need some experts - Dynamic Visualforce

Hello

 

I am having a really hard time solving this problem. I have tried Controller extensions and triggers but can't seem to make this work. Let me start from the beginning.

 

I created a Visualforce page with a Standard Controller using a customer object call Call Log. I have another object called ASI Solutions. I have been able to use a field called Solutions Type to dynamically populate with the Solution Type from the ASI Solutions object on the Visualforce page for the Call Log. This field populates based on a field on Call Log called Additional Details. Now I am trying to pull over a text field called Solution Details.

 

I have tried to pull over as a table, as a detail page within the edit page (I actually created another post with this code but never got a response), and now as a trigger. This trigger is supposed to assign the Solution to the Call Log.

 

I will post this code because I do need assitance with adding testing code. But overall if somebody could point me in the right direction or offer any words of advice I would really appreciate it.

 

trigger SolutionDetails on Call_Log__c (before insert, before update) { List<ASI_Solutions__c> addSolutions = new List<ASI_Solutions__c>(); for(Call_Log__c CL: trigger.new){ List <ASI_Solutions__c> selectedSolutions = [select Solution_Details__c from ASI_Solutions__c where Incident_Reference__c= : CL.Solution_Type__c];{ Solution_Details__c SD = CL.Solution_Type__c; For (Call_Log__c cl : selectedSolutions){ addSolutions.addAll(pList); } try{ insert addSolutions; } Catch (DmlException de){ for (Integer i = 0; I<de.getNumDml(); i++){ CL.addError(de.getDmlMessage(i)); } } updateSolutions.doUpdate(selectedSolutions); } } }

 

ShikibuShikibu

Hi rw,

 

I find that I can't understand your description of your data model or your code. Perhaps it would be better if you start by explaining what you're trying to accomplish in simple English?

 

I will offer two observations about your trigger: First, I suspect that you don't need a trigger at all, just a relationship between two objects. 

 

Second, the way you have written your trigger, it executes at least two DMLs per record (select, insert, and maybe more inside of class updateSolutions). This will get you into trouble with governor limits. Here are some examples of better practice for triggers. (But before you invest yourself in studying these, have another try at explaining your goal; I suspect you don't need a trigger at all.)

 

bulk trigger idioms

 

bulk trigger example

 

 

 

 

 

 

rwalrath144rwalrath144

I agree it would be best accomplished through a relationship but each way I have tried to display the field has not worked.

I have tried relationships between two objects and it doesn't work either. Ok I will try to explain again....

 

I have two objects Call Log and ASI Solutions. I created a Visualforce page with the standard controller of Call Log.

 

<apex:page standardController="Call_Log__c" tabStyle="Call_Log__c" sidebar="false" extensions="callsolutionExtension"> <apex:pageBlock > <h1>Welcome</h1> </apex:pageBlock> <apex:form > <apex:pageBlock title="New Call" id="thePageBlock" mode="Edit"> <apex:pagemessages ></apex:pagemessages> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Call Information"> <apex:inputField value="{!Call_Log__c.Invoice_Number__c}"/> <apex:inputField value="{!Call_Log__c.Who_is_calling__c}"/> <apex:inputField value="{!Call_Log__c.Client_with_Issue__c}" required="true"/> <apex:inputField value="{!Call_Log__c.Name__c}"/> <apex:inputField value="{!Call_Log__c.Caller_s_Phone_Number__c}"/> <apex:inputField value="{!Call_Log__c.Callers_Email__c}"/> </apex:pageBlockSection> <apex:actionRegion > <apex:pageBlockSection title="Issue/Questions Details"> <apex:inputField value="{!Call_Log__c.Primary_Reason_for_Call__c}"/> <apex:inputField value="{!Call_Log__c.Status_of_Order__c}"/> <apex:inputField value="{!Call_Log__c.Additional_Details__c}"> <apex:actionSupport event="onchange" reRender="dependentSolutionType"/> </apex:inputField> <apex:actionstatus id="solutionStatus" startText="Fetching Solution Types..."/> <apex:inputField value="{!Call_Log__c.Ship_Date__c}"/> </apex:pageBlockSection> <apex:pageblockSection id="dependentSolutionType"> <apex:pageBlockSectionItem > <apex:outputLabel value="Solution Type" for="sol"/> <apex:panelGrid columns="2"> <apex:outputText value="{!Call_Log__c.Solution_Type__c}" rendered="false"/> <apex:selectList id="sol" value="{!solutionTypes}" size="1"> <apex:selectOptions value="{!solutionTypeOptions}"/> </apex:selectList> </apex:panelGrid> </apex:pageBlockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Method of Shipping"/> <apex:outputPanel > <apex:inputField value="{!Call_Log__c.Method_of_Shipping__c}"> <apex:actionSupport event="onchange" reRender="thePageBlock" status="status"/> </apex:inputField> <apex:actionStatus startText="Applying value..." id="status"/> </apex:outputPanel> </apex:pageblockSectionItem> </apex:pageBlockSection> </apex:actionRegion> <apex:pageBlockSection > <apex:pageBlockSection title="Additional Comments"> <apex:inputField value="{!Call_Log__c.Comments__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Send Manual Email" columns="1" rendered="{!Call_Log__c.Method_of_Shipping__c == 'E-Cert'}"> <h1>Instructions:</h1> <p> Explain to the customer that the email may have been filtered and/or deleted without being seen. Let the customer know you will be sending a manual email to the recipient and be CCing them as well. If the customer asks further questions regarding the email explain that the email contains a link the recipient clicks on to retrieve the e-certificate.</p> <p><h1>IMPORTANT: In order for the email to be sent, the Sender's email address and Recipient's email address must be filled in.</h1></p> <p></p> <apex:inputField value="{!Call_Log__c.Send_Manual_Email__c}"/> <apex:inputField value="{!Call_Log__c.Senders_Email_Address__c}"/> <apex:inputField value="{!Call_Log__c.Recipients_Email__c}"/> </apex:pageBlockSection> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

I want the Solution Details field from ASI Solutions to be displayed on this Visualforce page too that coorelates with the Solution Type. There will be one record for every Solution Type that shows details of how resolve the issue. A couple of other details:

- ASI Solutions and Call Log are related - Call Log is the Child

- The Call Log will be in the Edit mode when the Solution Detail will be populated in

- There will be many Call Logs to one Solution but only one Solution to every Solution Type

 

I hope this clarifys things.

 

I am also posting the Controller Extension that controls the Solution Type field on the Visualforce page.

 

private final Call_Log__c call; public string solutionTypes {get; set;} public callsolutionExtension(ApexPages.StandardController callController){ this.call = (Call_Log__c)callController.getRecord(); solutionTypes = call.Solution_Type__c; } public List<selectOption> solutionTypeOptions {get { List<selectOption> solutionTypes = new List<selectOption>(); for (ASI_Solutions__c asr: [select sol.Id, sol.name, sol.Solution_Details__c from ASI_Solutions__c sol where sol.Incident_Reference__c = :call.Additional_Details__c order by name]) solutionTypes.add(new selectOption (asr.id, asr.name)); return solutionTypes; } private set;} }

 


 

ShikibuShikibu

Well, taking another look at some of your code, there seem to be more basic problems. For instance, your "Controller Extension that controls the Solution Type" has the return statement inside the body of the for loop; it will always return just one SelectOption (the one with the alphabetically lowest name). The select statement there also queries the Solution_Details__c field, but discards it. 

 

And the trigger that you posted earlier seems to be trying selecting data that is already present in the database and then trying to insert it again.

 

You say that Call Log is the child of ASI Solutions, but it seems perhaps Call Log just has a foreign key (a lookup) that references Solutions? That fits with your description that Call Log is many-to-one with Solution. When you say "only one Solution to every Solution Type", do you mean that solution type is a text field marked "unique"?

rwalrath144rwalrath144

The trigger isn't beinge used right now. It was a the last effort to solve my problem. The trigger can be disregarded.

 

I had the Solution Details be queried on purpose because I knew I need both fields. However I was never able to get the Solution Details to display.

 

Yes there is a foreign key lookup called Solution Type on Call Log to ASI Solutions. Yes the relationship is many to one. Solution Type is not the unique field for Solutions. ASI Solutions Name is the unique field.

 

Thank for taking your time to help me.

ShikibuShikibu

Hmm. Let me think out loud. A record in call log should be related to a single record in solution. (You should then have a field on call log named something like ASI_Solution_Id, which is your foreign key).

 

When your support staff is trying to determine which solution to relate the call record to, she figures out the solution type. ASI Soution object should have a field named Solution Type which is a picklist. 

 

You should provide a dropdown for solution type on the VF Call Log edit page (bound to an apex variable, not an SObject).

 

Then you need another dropdown for specific solutions of the type indicated in the solution type dropdown. Its options should have solution name as label, and solution id as value. It should be bound to call_log__c. solution_id__c (the foreign key).

 

Then also display an outputtext for call_log__c.solution_id__r.solution_detail__c.

 

 

You'll need the onchange event for the solution_type dropdown to populate and rerender the specific solutions dropdown. And you'll need the specific solutions dropdown to simply rerender the solution detail field (no querying, no triggering, no inserting; it's all handled by the FK relationship).

 

 

rwalrath144rwalrath144

Yes exactly except one detail.

 

When the agent is filling in the call log the Additional Details field is bound to the Solution Type field. So the agent doesn't have to figure our the Solution Type, it is provided depending on what is entered in the Additional Details field. I am trying to show the Solution Details from the solution record of that Solution type.

 

Confused yet. :smileyvery-happy:

ShikibuShikibu
You're losing me. In what way does a field name "additional details" determine a solution type? 
rwalrath144rwalrath144

The Extension queries ASI Solutions and gives a value for the picklist "Solution Type" when Call_Log__c.Additional_Details__c = ASI_Solutions__c.Incident_Reference__c.

 

Sorry for the names being the same but the lookup field is also called "Solution Type" that connects the two objects.