• Syed Noormohamad
  • NEWBIE
  • 5 Points
  • Member since 2016
  • Forsys


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hello,

Requirement: To update four picklist field values with dependencies. As the numbers of picklist values are high it’s difficult to manage the Field Dependencies manually.

 

Product Family

Product Line

Product Module

Product Version

 

Design Approach: So we planned to go for customization. We used four custom settings to store the picklist values. Then update the picklist fields values using Metadata API. Below are the design of four custom settings.

Product Family

Family1

Family2

Family3

 

Product Line

Family1 - Line1

Family2 - Line2

Family3 - Line3

 

Product Module

Line1 - Module1

Line1 - Module2

Line2 - Module2

 

Product Version

Module1 - Version1

Module2 - Version1

Module2 - Version2

 

Problem: Though the above design works for less volume of data, I am getting “System.LimitException: Apex CPU time limit exceeded” error when the number of picklist values is high (i.e. more than 1000).

 

I have generated a Metadata Service class from the MetadataAPI WSDL.

I need a map of following format to pass into "UpdateMetadata" method(in Metadata Service class).

Map<String, List<String>> OR Map<DependantValue, List<ControllingValues>>

 

To get the data in above format from custom setting, I am using below code.

 

Set<String> setDependantValue = new Set<String>();
        for(Product_Line__c objPicklistValues : lstProduct_Line){
            setDependantValue.add(objPicklistValues.Product_Line_Name__c);
        }
        Map<String, List<String>> mapDependantControllingValue = new Map<String, List<String>>();
        for(String objDepVal : setDependantValue){
            List<String> lstControllingValues = new List<String>();
            for(Product_Line__c objPicklistValues : lstProduct_Line){
                if(objDepVal == objPicklistValues.Product_Line_Name__c){
                    lstControllingValues.add(objPicklistValues.Product_Family_Name__c);
                }
            }
            mapDependantControllingValue.put(objDepVal, lstControllingValues);
        }

 

I think the error is coming due to FOR inside FOR loop.

Is there any other way to optimize the code or any solution?


Thank you

Swagat

 

 

Hi Everyone,

 

I'm new to working with Apex code and I have looked around for the answer to this but everyone seems to have a slightly different situation. I have the fields for a custom object displayed on a site that I want public users to be able to use to create new records. However, when I submit a new record it takes me to a logon page because it is attempting to take me to the new record. Instead I want it to take users to a page that says they successfully created a record. I have created a controller extension to override the save action but something is wrong with it as it does not even work on the VF page, I get the error "System.NullPointerException: Attempt to de-reference a null object" "Class.MyPageController.save: line 8, column 8 External entry point" , where line 8 is the "Insert request" line. I have been working from information on the two sites below. Any help would be greatly appreciated.

 

http://blog.jeffdouglas.com/2008/11/14/redirecting-users-to-different-visualforce-pages/

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

 

Site Code

<apex:page sidebar="false" showHeader="false" standardController="Request__c" extensions="MyPageController">   
<apex:form >
    <apex:pageBlock >
    <apex:pageMessages />
    <apex:pageBlockSection >
    <apex:detail />
        <apex:inputField value="{! Request__c.First_Name__c}" />
        <apex:inputField value="{! Request__c.Last_Name__c}"/>
        <apex:inputField value="{! Request__c.Email_Address__c}"/>
        <apex:inputField value="{! Request__c.Cost_Center__c}"/>
        <apex:inputField value="{! Request__c.Department__c}"/>
        <apex:inputField value="{! Request__c.Director_s_Email__c}"/>
        <apex:inputField value="{! Request__c.Director_s_First_Name__c}"/>
        <apex:inputField value="{! Request__c.Director_s_Last_Name__c}"/>
        <apex:inputField value="{! Request__c.Mailstop__c}"/>
        <apex:inputField value="{! Request__c.Phone_Number__c}"/>

    </apex:pageBlockSection>
    </apex:PageBlock>       
        <apex:commandButton action="{! save}" value="Save"/>
       
    </apex:form>
</apex:page>

 

Controller Extension

public class MyPageController {
Request__c request;
private ApexPages.StandardController controller;
public MyPageController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference save() {
insert request;
PageReference requestPage = Page.Congratulations;
requestPage.setRedirect(true);
return requestPage;

}

  • April 12, 2011
  • Like
  • 0