0

enter image description here

Just want to ask if it's possible to save the record on the first row if it's completely fill-up the 4 fields, and the 2nd row will be automatically deleted when there's no SkillName if you save that 2nd row. or in simple terms, skillName is the reference field in order to save the whole row. thanks in advanced!

Front End(VF Page)

<apex:column headerValue="Skill Name"><!--{!x}-->
                                 <apex:outputPanel styleClass="requiredInput" layout="block">
                                    <apex:outputPanel styleClass="requiredBlock" layout="block"/>
                                    <apex:inputField id="Skill" value="{!esw.esforWrapper.Skill_ID__c}" required="{!sNameRequired}">
                                          <apex:actionSupport event="onchange" action="{!isItRequiredSkl}" reRender="none" immediate="true"> 
                                            <apex:param name="sName" value="{!esw.esforWrapper.Skill_ID__c}" assignTo="{!skillName}" />
                                         </apex:actionSupport>

                                    </apex:inputField>
                                 </apex:outputPanel>
                             </apex:column>

Controller

      public void populateSkill(){
        Set<ID> empSkillIDSet = new Set<ID>();
        totalESList.clear();
        try{
            for (EmpSkillWrapper wc : esWrapper){
                Employee_Skills__c e1 = new Employee_Skills__c();

                if (wc.esforWrapper.Skill_ID__c != null) {
                    e1.Skill_ID__c = wc.esforWrapper.Skill_ID__c;
                }               

                if (wc.esforWrapper.Proficiency__c != null) {
                    e1.Proficiency__c = wc.esforWrapper.Proficiency__c;        
                }           

                if (wc.esforWrapper.Skill_Type__c != null) {
                    e1.Skill_Type__c = wc.esforWrapper.Skill_Type__c;
                }             

                if (wc.esforWrapper.Year_of_Experience__c != null) {
                    e1.Year_of_Experience__c = wc.esforWrapper.Year_of_Experience__c;                    
                }  

                if (e1.Skill_ID__c != null && e1.Proficiency__c != null && e1.Skill_Type__c != null && e1.Year_of_Experience__c != null) {
                    system.debug('esList ' + totalESList);
                    totalESList.add(e1); 
                }

            }

        }

        catch (Exception e){

            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
            ApexPages.addMessages(e); 
        }

        for(Integer i=0; i<totalESList.size(); i++)
        {
            empSkillIDSet.add(totalESList.get(i).Skill_ID__c);
        }

        if(empSkillIDSet != null){
            if(empSkillIDSet.size() < totalESList.size()){

                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please remove duplicate skill');
                ApexPages.addMessage(myMsg);
                flag = true;
            }
        }  
    }

    public void isItRequiredSkl() {
    if (skillName == null) {
        clearLists();
        skillTypeRequired = false;
        yoeRequired = false;
        proficiencyRequired = false;              
    } 

    if (skillName != null) {
        skillTypeRequired = true;
        yoeRequired = true;
        proficiencyRequired = true;
    }



   }

    public void populateListsWithContactId(Contact contact){
        boolean isNotNull = false;
        if(totalESList != null){

            for(Employee_Skills__c es: totalESList){
                es.Employee_ID__c = contact.Id;
                isNotNull = true;
            } 
        }

        if (isNotNull == true){
            upsert totalESList;
        }
   }


    public void clearLists(){
        totalESList.clear();
    }

    public PageReference CreateProfileTab6(){

        flag=false;
        try{

            if((esWrapper.get(0).esforWrapper.Skill_ID__c != null) &&
                (esWrapper.get(0).esforWrapper.Skill_Type__c != null) &&
                (esWrapper.get(0).esforWrapper.Proficiency__c != null) &&
                (esWrapper.get(0).esforWrapper.Year_of_Experience__c != null)){
                populateSkill();
            } 


            if(!flag){
                    // customSecQuest is just an security question to fill-up
                    customSecQuest();
                    c.AccountId = '0012800001B2ofk'; 
                    insert c;
                    populateListsWithContactId(c);
                    pageRef = new PageReference('/'+c.Id); 
                    pageRef.setRedirect(true);
            }else{
                pageRef = new PageReference(PAGE_CREATE_NEW_PROFILE); 
                pageRef.setRedirect(false);  
            }

        }catch(Exception e){
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
            ApexPages.addMessage(myMsg);
            clearLists(); 
        } 

        pageRefresh = true;
        return pageRef;
    }
  • Can you share your code which your approach. By the way your requirement is achievable. – Santanu Boral May 3 '17 at 4:43
  • Hi @SantanuBoral how could I edit my post here? so that I could attached my codes together with the picture. thanks! – boy george May 3 '17 at 4:46
  • you can see the "edit" link to edit to question – Santanu Boral May 3 '17 at 4:49
  • You can have validation rule to mandate the Skill Type and then while inserting the records use Database.Insert(yourList, false); Records which don't pass the validation rule will not be inserted anyway, rest will be inserted. – Santanu Halder May 3 '17 at 6:40
  • @SantanuBoral but the thing is, I have a reference object before I could save this skill, I must have a Personal Info record, and eventhough I've not set an skill, I could still save Personal Info. So I must not mandate it to required, is it possible? – boy george May 3 '17 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.