• SUPRAKASH Marandi
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I have created custom multipicklist jQuery. In the multipicklist I have shown the contact names. Whenever I select the contact names, it is showing contact names in the label. It is also counting no.of contacts I have selected.
Activity Objective==> Wherever you see Activity Objective in the VFP, I have added the codes for the multi-picklist.
ISSUE: whenever I select the contact names (either 1 or more than 1) from the multi-picklist and click on save. It will save the record, but in the name field in the Task object will be blank. If I have selected 1 0r more than 1 contact names, it will create single record in the Task object and the name field will be blank.
REQUIREMENT: Now I want that, how many contact names I have selected from the multi-picklist. That many records will be created in the Task Object.
Already in the controller, record creation code is written. It is checking the contact name isChecked=true, then it will create the record.
In my code, it is taking isChecked=false. So it is not able to creat
<apex:page standardController="Task" id="thePageId" extensions="NewTaskCtrl" tabStyle="Task" action="{!loadNewTask}">
    <apex:outPutPanel id="myMSG">
        <apex:pageMessages id="msg" />
    </apex:outPutPanel>  
    <apex:slds />
    <apex:form id="newTaskPage">
             <!-- CDN links for the multiple picklist  -->
                <meta charset="utf-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
                <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
                <link href="https://www.jqueryscript.net/css/jquerysctipttop.css?v3" rel="stylesheet" type="text/css" />
                <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"/>
                <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>                
                <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
                <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
                <script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.40/dist/js/BsMultiSelect.min.js"></script>              
                <!-- / Activity Objective - New picklist code-->

                <apex:actionFunction action="{!filterFields}" name="filterFields" reRender="myMSG,taskInfo" >
                    <apex:param value="" name="tType" />
                </apex:actionFunction>
                <apex:sectionHeader title="Task" subtitle="New Task"/>
                <apex:inputHidden value="{!inputValue}" id="theHiddenInput"/>
                <div class="slds-card">
                    <div class="slds-card__header slds-grid slds-border_bottom slds-p-bottom_small" style="background-color: #fafaf9;">
                        <div class="slds-media slds-media_center slds-has-flexi-truncate">
                            <div class="slds-media__body">
                                <h2 class="slds-card__header-title slds-text-heading_small">
                                    Task Edit
                                </h2>
                            </div>
                            <div class="slds-no-flex">
                                <apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
                                <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
                            </div>
                        </div>
                    </div>
                    <div class="slds-card__body slds-p-horizontal_small">
                        <div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Related To</strong></div> 
                        <div class="slds-form slds-form_horizontal">
                            <div>
                                <div style="max-width: 600px;">
                                    <apex:outputPanel styleClass="relatedToSection">
                                        <div class="slds-form-element">
                                            <apex:outputLabel value="Account" styleClass="slds-form-element__label"/>
                                            <div class="slds-form-element__control slds-m-top_xxx-small">
                                                <apex:outputField value="{!taskObjectParent.WhatId}" title="This will contain Related Account" label="Account" />
                                            </div>
                                        </div>

                                        <apex:pageBlock id="OfficeContactList">
                                            <!--  rendered="{!IF((taskObjectParent.Id = null),true,false)}"  -->
                                            <apex:outputPanel style="display:none" styleclass="taskContactMultiList">


                                                <div class="slds-form-element">
                                                    <apex:outputLabel value="Select Contact to create task" styleClass="slds-form-element__label" id="con12"/>
                                                    <div class="slds-form-element__control"  style="padding-right: 82px;">
                                                        <!-- Activity Objective  -->
                                                        <!-- Show the multiple picklist values and binding-->
                                                        <div class="container">
                                                            <select name="contactNames" id="example" class="form-control" multiple="multiple" onChange="countSelectedCheckbox()">
                                                                <apex:repeat value="{!avaiableContactlList}" var="con" id="conTable">
                                                                    <option value="{!con.isChecked}" id="opt">{!con.Name}</option> <!---value is changed -->
                                                                </apex:repeat>
                                                            </select>    
                                                        </div>
                                                        <!-- / Activity Objective -->

                                                        Total Number of Selected record :<span style="font-weight:bold" id="selContactSize">0</span>
                                                    </div>
                                                </div>

                                            </apex:outputPanel>

                                        </apex:pageBlock>     

                                    <div class="slds-form-element">
                                        <apex:outputLabel value="Topics Discussed" styleClass="slds-form-element__label"/>
                                        <apex:outputPanel id="refreshing">
                                            <div class="slds-form-element__control"  style="padding-right: 82px;">
                                                <div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
                                                    <table>

                                                        <apex:repeat value="{!avaiableTopicList}" var="topic">
                                                            <tr>
                                                                <td width="20" class="slds-p-bottom_x-small">
                                                                    <span class="slds-checkbox slds-checkbox_standalone">
                                                                        <apex:inputCheckbox value="{!topic.isChecked}" onclick="selectAllCheckboxes('topicCheckBoxId')"  id="topicCheckBoxId"/>
                                                                        <span class="slds-checkbox_faux"></span>
                                                                    </span>
                                                                </td>
                                                                <td class="slds-p-bottom_x-small">
                                                                    <label>
                                                                        {!topic.Name}
                                                                    </label>
                                                                </td>
                                                            </tr>
                                                        </apex:repeat> 
                                                    </table>

                                                </div>
                                                Total Number of Selected record :<span style="font-weight:bold" id="selTopicSize">{!totalAvaiableTopic}</span> 
                                            </div>
                                        </apex:outputPanel>
                                    </div>

                                </div>
                            </div>


                        </div> 

                    </div>
                    <div class="slds-card__footer slds-text-align_right">
                        <apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
                        <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>  
                    </div>
                </div>
                <script>
                function setFocusOnLoad() {}

                function toggleComponent(taskType,componentToToggle,taskId){
                    console.log('taskId : '+taskId);
                    //filterFields();
                    if(taskId == 'NULL' || taskId == ''){
                        var contactComponent = document.getElementsByClassName(componentToToggle)[0];
                        var selectedValue = taskType.value;
                        console.log(componentToToggle);
                        if(selectedValue == 'Physician-to-Physician Visit' || selectedValue == 'Sports Medicine' ){
                            contactComponent.style.display ='block';

                        }else{
                            contactComponent.style.display ='none';
                        }
                    }else{
                        var contactComponent = document.getElementsByClassName(componentToToggle)[0];
                        var selectedValue = taskType.value;
                        console.log(componentToToggle);
                        var oldTaskType =  String(document.getElementById('thePageId:newTaskPage:theHiddenInput').value);

                        if((oldTaskType != 'Physician-to-Physician Visit' && selectedValue == 'Physician-to-Physician Visit') || (oldTaskType != 'Sports Medicine' && selectedValue == 'Sports Medicine')){
                            contactComponent.style.display ='block';

                        }else{ 
                            contactComponent.style.display ='none';
                        }
                    }
                    //alert(taskType.value);
                    filterFields(taskType.value);
                }

                function selectAllCheckboxes(receivedInputID){
                    var inputCheckBox = document.getElementsByTagName("input");
                    var totalCount = 0;
                    for(var i=0; i<inputCheckBox.length; i++){
                        if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                            if(inputCheckBox[i].checked == true){
                                //alert("inputCheckBox[i].checked==>>"+inputCheckBox[i].checked);
                                totalCount = totalCount + 1;
                            }
                        }
                    }

                    //console.log('====>' + totalCount);
                    if(receivedInputID=='contactCheckBoxId'){
                        document.getElementById('selContactSize').innerHTML = totalCount;
                    }else if(receivedInputID=='goalCheckBoxId'){
                        document.getElementById('setGoalsLength').innerHTML = totalCount;
                    }else if(receivedInputID=='topicCheckBoxId'){
                        document.getElementById('selTopicSize').innerHTML = totalCount;
                    }

                }


                // Js file to show the multiple picklist.
                $("select[multiple='multiple']").bsMultiSelect();

                // code to calculate the count of selected picklist values
                **function countSelectedCheckbox(){
                    var totalCount = $("select#example>option:selected").length;
                    document.getElementById('selContactSize').innerHTML = totalCount;
                    }
                </script>
    </apex:form>
</apex:page>

e the record. Due to limitation, not able to upload whole code.
Hi Team,

This is the Class and when i run the class it through the error....
 
@isTest              
public class LeadOpportunityTest 
{
    static testMethod void LeadTestmethod()
    {
        RecordType LeadRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Lead' AND Name = 'IPL'
                                         LIMIT 1];
        Lead leadVar=new Lead(LastName='Singla',FirstName='Dinesh',Company='Infosys',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='RR',Email='dinesh.singla24@gmail.com',
                              RR_vs_CSK__c=true,RR_vs_RCB__c=true,RR_vs_KXIP__c=true,RR_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar;
         Lead leadVar1=new Lead(LastName='kumar',FirstName='Raj',Company='invoice',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='MI',Email='dinesh.singla24@gmail.com',MI_vs_RR__c=true
                               ,MI_vs_DD__c=true,MI_vs_KXIP__c=true,MI_vs_KKR__c=true,MI_vs_RCB__c=true,MI_vs_CSK__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar1;
         Lead leadVar2=new Lead(LastName='Farhan',FirstName='akhtar',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='CSK',Email='dinesh.singla24@gmail.com',CSK_vs_RR__c=true,CSK_vs_DD__c=true
                               ,CSK_vs_KXIP__c=true,CSK_vs_KKR__c=true,CSK_vs_RCB__c=true,CSK_vs_SRH__c=true,CSK_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar2;
         Lead leadVar3=new Lead(LastName='Prasad',FirstName='Madhvan',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='KXIP',Email='dinesh.singla24@gmail.com',KXIP_vs_DD__c=true
                               ,KXIP_vs_KKR__c=true,KXIP_vs_RR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar3;
         Lead leadVar4=new Lead(LastName='Rohirt',FirstName='sharma',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='DD',Email='dinesh.singla24@gmail.com',DD_vs_RR__c=true,DD_vs_RCB__c=true
                               ,DD_vs_KXIP__c=true,DD_vs_MI__c=true,DD_vs_KKR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar4;
        
    }
    static testMethod void OpportunityTestmethod()
    {
        
        Account accVar=new Account(name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar; 
        RecordType oppDiabetesRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(name='Infosys',Accountid=accVar.id,Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppDiabetesRecordType.id);
        insert oppVar;
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        oppVar.StageName='Payment Received';
        oppVar.Payment_Received__c=true;
        oppVar.Transaction_Reference_No__c='transaction';
        oppVar.Customer_Payment_Date__c=Date.Today();
        oppVar.Booking_Ids__c='bookingid';
        update oppVar;
        system.debug('....update opportunity.........'+oppVar);
    
    }
    static testMethod void OpportunityTestmethodPaymentConfirm()
    {
        Account accVar=new Account(Name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar;
        RecordType oppRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(Name='Infosys',Accountid=accVar.id,  Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppRecordType.id);
        insert oppVar;
        
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        
         oppVar.StageName='Payment Confirmation';
         oppVar.Customer_Payment_Confirmed__c=true;
         oppVar.Checked_By__c=UserInfo.getUserId();
         oppVar.Payment_Received_on__c=Date.Today();
         oppVar.Amount_Received__c=55555;
         oppVar.Booking_Ids__c='bookingid';
          update oppVar;
    }
}

 
i write a program in this way but it gives an error

program:
list<student__c>stlist=new list<student__c>();
list<sports__c>splist=new list<sports__c>();
list<library__c>liblist=new list<library__c>();
list<student__c>stlist=[select id, Name, email__c, fee__c, sports__r.sports_name__c, sports__r.sports_cost__c, sports__r.sports_type__c, sports__r.libraries__r.Name, sports__r.libraries__r.book_type__c, sports__r.library__r.book_amount__c from student__c where country__c='INDIA'];
for(student__c st:stlist)
{
    system.debug('student record is' +st);
    system.debug('sports record is' +st.sports__r);
     system.debug('library record is' +st.sports__r.library__r);
    st.state__c='AP';
    st.city__c='hyd';
    st.email__c='ABC@cap.com';
    stlist.add(st);
    st.sports__r.sports_cost__c=1000;
    st.sports__r.sports_type__c='cricket';
    splist.add(st.sports__r);
    st.sports__r.library__r.book_type__c='technical';
    st.sports__r.library__r.book_amount__c=999;
    liblist.add(st.sports__r.library__r);
}
if(stlist.size()>0 && stlist!=null)
    update stlist;
if(splist.size()>0 && splist!=null)
    update splist;
if(liblist.size()>0 && liblist!=null)
    update liblist;

error:
Didn't understand relationship 'sports__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
please give me a solution