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
Vanitha ManiVanitha Mani 

Change lookup to picklist based on value in case detail page

Hi,
  <lightning:recordEditForm recordId ="{!v.recordId}" objectApiName = "Case" aura:id="leadCreateForm1" onload="{!c.Onload}" >
        <lightning:messages />
          
 
        <lightning:inputField fieldName="Solution__c" required ="true"/>
           
            <lightning:inputField fieldName="Product_Build__c" required ="true" />
             <lightning:inputField fieldName="System_Version__c" required ="true" />
           
            <lightning:inputField fieldName="Feature_Function__c" required ="true" />
Here feature is a lookup field in case..I need to change it to picklist based on the value selected in product field in case page..i used custom lookup component but there is a condition that the picklist values depends on value in product field .
    public List<SelectOption> getFeatureFunction(){
        List<SelectOption> FeatureFunction = new List<SelectOption>();
        if(selProductId!=null){

            //Feature Functions related to Selected Product
            for(SVC_Feature_Function__c FF : [Select Id, Name From SVC_Feature_Function__c WHERE Product__c=:selProductId order by Name asc])
                FeatureFunction.add(new SelectOption(FF.Id,FF.Name));
        }
        return FeatureFunction;
    }

.Can anyone help me with this code?

Thanks
 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vanathi,

Can you elaborate on the issue you are facing to look further and respond back?

Looking forward to your response.

Thanks.
Vanitha ManiVanitha Mani
Hi,

I have product field in ticket page.
User-added image

Based on the  value given in product field..Feature_Function__c" field should get populated..it is a lookup field and i need the values as a picklist..i implemented in VF page but i need to do in aura lightning component now.I will paste VF page code for it.

<label class="slds-form-element__label" style="margin-top: 1%;" for="text-input-01">
                                <abbr class="slds-required" style="color: red;" title="required">*</abbr> Failure Point :</label>
                            <div class="slds-form-element slds-lookup" data-select="single">
                                <div class="slds-form-element__control" style="width: 100%;">
                                    <div class="slds-input-has-icon slds-input-has-icon--right">
                                        <apex:actionRegion >
                                            <apex:outputPanel id="FeatureFunction1">

                                                <apex:selectList label="FeatureFunctions" required="false" id="drpFeatureFunction" value="{!selFeatureFunctionId}" html-data-live-search="true" styleClass="selectpicker show-tick form-control" html-data-actions-box="true" html-data-done-button="true">

                                                    <apex:selectOption html-data-hidden="true" itemValue="" itemLabel="Nothing Selected"/>
                                                    <apex:selectOptions value="{!FeatureFunction}"/>
                                                </apex:selectList>

                                            </apex:outputPanel>
                                            <apex:actionFunction name="refreshFeatureInfo" action="{!getFeatureInfo}" rerender="Output,Other" oncomplete="" status="actionStatusID"/>
                                        </apex:actionRegion>
                                    </div>
                                </div>
                            </div>

                            <apex:outputPanel id="Output">
                                <apex:outputText style="style=font-style: italic; font-weight: bold; color: red;" value="{!OutPutText} Reason" rendered="{!IF(OutPutText=='Other',true,false)}"> </apex:outputText>
                            </apex:outputPanel>


                            <apex:outputPanel id="Other">
                                <label class="slds-form-element__label" for="textarea-input-01"  >
                                    <abbr class="slds-required" style="color: red;"  title="required" > </abbr> </label>
                                <div class="slds-form-element__control">
                                    <apex:inputField value="{!objCase.FF_Other__c}" required="False" styleClass="slds-textarea slds-required" rendered="{!IF(OutPutText=='Other',true,false)}"  label="Other Reason"/>
                                </div>
                            </apex:outputPanel>


controller:

public class SVC_TicketResolve_Ctl{
    public List<String> REQUIRED_PROACTIVE_MI_SYSTEM_NAMES {get{return new List<String>{'SystemWatch Alert'};}}
    public Boolean isProactiveMIRequired{get{return REQUIRED_PROACTIVE_MI_SYSTEM_NAMES.contains(objCase.Origin);}}
    public boolean isBillable{get;set;}
    public Id selSystemId{get;set;}
    public Id selProductId{get;set;}
    public Id selChangeReqId{get;set;}
    public Id SelFeatureFunctionId{get;set;}
    public Case objCase{get;set;}
    public Id CaseId;
    public SVC_Work_Time__c ObjWorkTime {get;set;}
    public date contractExpirationDate{get;set;}
    public string OutPutText{get;set;}
    public Boolean isWorkTimeReasonRequired{get;set;}

//    TKT-1153378
    public PageReference workTimeMinutesChanged(){
        isWorkTimeReasonRequired = ObjWorkTime.Minutes__c != null && ObjWorkTime.Minutes__c != 0;
        return null;
    }
//    TKT-1153378

    public SVC_TicketResolve_Ctl(ApexPages.StandardController controller) {
        isBillable = false;
        ObjWorkTime = new SVC_Work_Time__c();

//        TKT-1153378
        workTimeMinutesChanged();
//        TKT-1153378

        CaseId = apexPages.CurrentPage().getparameters().get('id');

        //Get Ticket record from page id
        //Ticket Enhancement W-000250 -- Added subquery for getting linked products
        objCase =[Select id,Account.Name,Account.Billable_Maintenance_Agreement__c,Contact.Name,Ticket_Number_Link__c,Solution__c,FF_Other__c,SolvedBy__c,
                CauseCodeCategory__c,CauseCodeDetail__c,Caused_By_Change__c,/*Change_Request__c,*/CaseNumber,Total_Time_to_Resolve_Minutes__c,
                Reason,Total_Work_Time__c,Billing_Type__c,Billing_Status__c,Billing_Hours__c,Billing_Comments__c,Billing_Disposition__c,Product_Build__c,//Ticket Closure / BSPRJ-9
                SVC_Change_Request__c,Status,RecordType.DeveloperName,Billable__c,Subject,Urgency__c,Impact__c,Origin,Proactive_MI_Prevention_or_Resolution__c,
        (select Id,Name,Product_Build__r.Name,System_Version__c from Ticket_Product_Build_Link__r limit 1),//Ticket Closure / BSPRJ-9
                Invoice_Number__c,Invoice_Notes__c,Invoice_Paid__c,System__c,Feature_Function__c,Product__c from Case where id =:CaseId ];

        //Populate dropdown from selected ticket
        selSystemId = objCase.System__c;
        selProductId = objCase.Product__c;
        selFeatureFunctionId = objCase.Feature_Function__c;
        selChangeReqId = objCase.SVC_Change_Request__c;
        isBillable = objCase.Billable__c;

        system.debug(objCase.Feature_Function__c);


        //Set Status depending on the record type of ticket
        if(objCase!=null && objCase.RecordType.DeveloperName=='Systems_Service_Request'){
            //Begin of insert Systems On-Hold Removal Project
            objCase.Status = 'Resolved';
            //End of insert Systems On-Hold Removal Project
            //Begin of Removal Systems On-Hold Removal Project
            //objCase.Status = 'Closed';
            //End of Systems On-Hold Removal Project
        }
        else if(objCase!=null && objCase.RecordType.DeveloperName=='Systems_Incident'){
            objCase.Status = 'Resolved';
        }
    }
    //get System Dropdown options
    public List<SelectOption> getSystems(){
        List<SelectOption> systemSelectOptionList = new List<SelectOption>();
        if(objCase.RecordType.DeveloperName =='Systems_Incident'){
            for(SVC_System__c objSys : [select Id,Name from SVC_System__c where Systems_Incidents__c=true order by Name limit 500])
                systemSelectOptionList.add(new SelectOption(objSys.Id,objSys.name));
        }else{
            for(SVC_System__c objSys : [select Id,Name from SVC_System__c where Systems_Service_Requests__c=true order by Name limit 500])
                systemSelectOptionList.add(new SelectOption(objSys.Id,objSys.name));
        }

        return systemSelectOptionList;
    }
    //get product dropdown options
    public List<SelectOption> getProducts(){
        List<SelectOption> products = new List<SelectOption>();
        if(selSystemId!=null){

            //Products related to Selected system
            for(Svc_Product__c prd : [select Id,Name from Svc_Product__c where System__c=:selSystemId order by Name asc])
                products.add(new SelectOption(prd.Id,prd.Name));

        }
        return products;
    }
    //get Feature Functions dropdown options TKT-1008939
    public List<SelectOption> getFeatureFunction(){
        List<SelectOption> FeatureFunction = new List<SelectOption>();
        if(selProductId!=null){

            //Feature Functions related to Selected Product
            for(SVC_Feature_Function__c FF : [Select Id, Name From SVC_Feature_Function__c WHERE Product__c=:selProductId order by Name asc])
                FeatureFunction.add(new SelectOption(FF.Id,FF.Name));
        }
        return FeatureFunction;
    }
    //get change request dropdown options
    public List<SelectOption> getChangeRequests(){
        List<SelectOption> requests = new List<SelectOption>();
        System.debug('selSystemID>>>>'+selSystemID);
        if(objCase.AccountId!=null){

            //Get change requests related to selected account
            for(SVC_Change_Request__c cr : [select Id,Name from SVC_Change_Request__c where Account__c=:objCase.AccountId])
                requests.add(new SelectOption(cr.Id,cr.Name));

        }
        return requests;
    }
    //save ticket & work time
    public pagereference saveTicket(){
        Savepoint sp = Database.setSavepoint();
        try{
            if(objCase != null)
            {
                objCase.Billable__c = isBillable;
                objCase.SVC_Change_Request__c=selChangeReqId;
               objCase.Product__c = selProductId;
               objCase.Feature_Function__c = selFeatureFunctionId;
                //Insert worktime if value populated
                if(ObjWorkTime != null && ObjWorkTime.Minutes__c!=null && ObjWorkTime.Reason__c!=null){
                    if(ObjWorkTime.Ticket__c==null){
                        ObjWorkTime.Ticket__c = objCase.id;
                    }
                    System.debug('Insert ObjWorkTime --->'+ObjWorkTime);
                    insert ObjWorkTime;
                }

                update objCase;
                return new pagereference('/'+objCase.Id);
            }
        }
        catch(Exception e){
            Database.rollback( sp );
            System.debug(e);
            //To avoid exception as we are rolling back the dml operation
            ObjWorkTime.Id=null;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,e.getMessage(),''));
            return null;
        }
        return null;
    }
    //Open ticket detail page
    public Pagereference openTicketDtls(){
        Pagereference ticketDetail = new Pagereference('/'+CaseId);
        ticketDetail.setRedirect(true);
        return ticketDetail;
    }
    //Get contract expiration date from System
    public pagereference getSystemInfo(){
        if(selSystemId!=null){
            SVC_System__c objSys = [select Id,Name,(select Id, EndDate from Service_Contracts__r order by EndDate Desc limit 1) from SVC_System__c where Id=:selSystemId];
            objCase.System__c = objSys.Id;

            //Check if service contract exist for selected system
            if(objSys.Service_Contracts__r.size()>0)
                contractExpirationDate = objSys.Service_Contracts__r[0].EndDate;
        }
        else
                contractExpirationDate = null;
        return null;
    }
    //Get Product info TKT-1008939
    public pagereference getProductInfo(){
        if(selProductId!=null){
            SVC_Product__c objProd = [Select Id, Name FROM SVC_Product__c where Id=: selProductId];
            objCase.Product__c = objProd.Id;






        }
        return null;
    }
    // To find if outputtext = "Other" on VFP to display Other input field, if failure point/feature function selected is "Other" TKT-1008939 -->
    public pagereference getFeatureInfo(){
        if(selFeatureFunctionId!=null){
            SVC_Feature_Function__c objfeature = [Select Id, Name FROM SVC_Feature_Function__c where Id=: selFeatureFunctionId];
            OutPutText = objfeature.Name;


        }
        return null;
    }
}
Thanks

I need same output like in VF page 
User-added image

But in aura lightning component.it is like lookup field..i need to change it to picklist but the options is based on the product field value in case page.

User-added image
 
Vanitha ManiVanitha Mani
Can anyone help me with this code