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
Hugo SoaresHugo Soares 

Set up different opportunity page layouts

Hello, 
When I create an opportunity, I send a request to an external service that tells me which fields are going to be shown in that opportunity's layout.
Because the fields are dynamically created, different layouts will be created for different opportunities.
The problem is that when I create a new field and add it to the opportunity layout, all opportunity layouts are affected.

I'm aware that I can have several record types and assign different layouts to different profiles, however, I'd like to be able to sign in with my admin account and click on every opportunity and see the different layouts without having to change profile.

Is this possible?

Regards,

Hugo Soares
 

Best Answer chosen by Hugo Soares
Harpreet On CloudHarpreet On Cloud
So as I understand, it would be something like this 1. You override the New button on Opportunity to open a VF page. 2. When you click New button, the Custom Controller of the VF page is called. 3. The custom controller makes a call to external service to retrieve details of which field to display. 4. VF page displays only those fields along with the mandatory fields like Name, Close Date etc. 5. After entering data on the displayed fields only, user clicks Save button on VF page. It goes to Custom Controller Save method that saves the record along with the information, on the record itself, about which fields should be displayed. Since after saving, we would need to display only the fields that were displayed on the Create page, so we will have to override the View action too. 6. Override the View action on Opportunity to another VF page. 7. Based on the information stored on the Opportunity record about which fields to display (step 5 above), the VF page displays only those fields in Read mode. Same goes for Edit Mode. Actually if properly designed, for Edit mode, you should be able to re-use the VF page used for Create mode. I hope this helps. - Harpreet

All Answers

Harpreet On CloudHarpreet On Cloud
Are you considering a custom UI using VF page / Lightning Component. The kind of minute control you want would be easier done using a custom implementation. If, rather than controlling visibility of each field, the external service decides which set-of-fields would be visible or hidden, you can use field sets too as part of custom implementation. This way, you can still have control over which field is shown.

- Harpreet
Hugo SoaresHugo Soares

The problem is that SF has no clue about which fields or how many fields are going to be shown. That decision, and others, like the name and the type of field, is made by the external sevice. This external service analysis a product and tells SF to add specific fields to the opportunity's layout.

Therefore, it's not about field visibility because the fields are always changing and I could be adding different fields everytime I create a new opportunity.

Harpreet On CloudHarpreet On Cloud
So it does make sense to create a VF page to control which fields are shown on the page and which not, based on the information received from external service. So rather than controlling field visibility at the profile level, field visibility can be managed at the vf page level.
Hugo SoaresHugo Soares
So let's say I create a new opportunity with fields I get from the request I made to the external service... What you're saying is that those fields have to get linked to that specific opportunity so that everytime I open the opportunity, SF knows which fields to display?
Harpreet On CloudHarpreet On Cloud
So as I understand, it would be something like this 1. You override the New button on Opportunity to open a VF page. 2. When you click New button, the Custom Controller of the VF page is called. 3. The custom controller makes a call to external service to retrieve details of which field to display. 4. VF page displays only those fields along with the mandatory fields like Name, Close Date etc. 5. After entering data on the displayed fields only, user clicks Save button on VF page. It goes to Custom Controller Save method that saves the record along with the information, on the record itself, about which fields should be displayed. Since after saving, we would need to display only the fields that were displayed on the Create page, so we will have to override the View action too. 6. Override the View action on Opportunity to another VF page. 7. Based on the information stored on the Opportunity record about which fields to display (step 5 above), the VF page displays only those fields in Read mode. Same goes for Edit Mode. Actually if properly designed, for Edit mode, you should be able to re-use the VF page used for Create mode. I hope this helps. - Harpreet
This was selected as the best answer
Hugo SoaresHugo Soares

Your answer really helped me a lot, thank you very much for your time and patience!!
- Hugo Soares