Create a Custom Lightning Component for Show Approve/Reject Status of Selected Records through Modal Popup in Salesforce Lightning Component | custom approval process in salesforce lightning component

3,968 views

Hey guys, today in this post we are going to learn about how toCreate a Custom Lightning Component for Show Approve/Reject Status of Selected Records through Modal Popup in Salesforce Lightning Component.

Files we used in this post example

approveRejectApp.app Lightning Application It is used for call theΒ component to previewΒ on browser.
approveRejectCmp.cmp Lightning Component It is used for create a table for display the Buttons and Table Row Data
approveRejectCmpController.js JavaScript Controller File It is hold Javascript Click Function to display Approve/Reject Status
approveRejectCmpHelper.js JavaScript Controller Helper File It is hold for Javascript Click Function to display Approve/Reject Status
approveRejectCmp.css Component Style CSS It is used for Alignment of Table and Buttons

Live Demo

Approve/Reject Status In Lightning Component -- w3web.net

 

You can download file directly from github by Click Here.

 

 

Other related post that would you like to learn in Salesforce

 

Create Lightning Application

Step 1:- Create Lightning Application : approveRejectApp.app

From Developer Console >> File >> New >> Lightning Application

approveRejectApp.app [Component Application File]

  1.   <aura:application extends="force:slds">
  2.     <c:approveRejectCmp/>
  3. </aura:application>

Create Lightning Component

Step 2:- Create Lightning Component : approveRejectCmp.cmp

From Developer Console >> File >> New >> Lightning Component

approveRejectCmp.cmp [Lightning Component File]

  1.   <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
  2. 	<aura:attribute name="rejectDocumentMsg0" type="String"/>
  3.     <aura:attribute name="rejectDocumentMsg1" type="String"/>
  4.     <aura:attribute name="rejectDocumentMsg2" type="String"/>
  5.     <aura:attribute name="rejectDocumentMsg3" type="String"/>
  6.     <aura:attribute name="rejectDocumentMsg4" type="String"/>
  7.  
  8.     <aura:attribute name="dataRowModal" type="String" default="dataRowModal"/>
  9.     <div class="slds slds-p-horizontal--medium">
  10.        <div class="test-id__section slds-m-vertical_none slds-section has-header slds-p-bottom_medium"> 
  11.            <h3 class="test-id__section-header-container slds-section__title">Approve/Reject Status</h3>
  12.         </div>   
  13.         <table width="100%" class="slds-table slds-table_bordered  slds-table_cell-buffer" border="0" style="border:1px #ddd solid;">
  14.             <tbody> 
  15.                 <tr class="dataRowIcon" id="dataRowIcon0">
  16.                     <td><div style="width:35px;"><span class="approvalIcon"><lightning:icon iconName="action:approval" size="xx-small" alternativeText="approval"/></span> <span class="rejectIcon"><lightning:icon iconName="action:close" size="xx-small" alternativeText="Reject"/></span></div></td>
  17.                     <td width="20%">Content Approval  </td>
  18.                     <td width="30%"><a href="#" target="_blank" rel="noopener noreferrer">Approval Documents</a></td>
  19.                     <td width="30%"><div class="slds-truncate" style="max-width:200px;">{!v.rejectDocumentMsg0}</div></td>
  20.                     <td width="20%">
  21.  
  22.                         <button class="slds-button slds-button--success" id="approve" name="dataRowIcon0" onclick="{!c.approveAction}">Approve</button>
  23.                         <button class="slds-button slds-button--destructive" name="dataRowIcon0" onclick="{!c.rejectAction}">Reject</button>
  24.                     </td>
  25.                     <td colspan="5">
  26.  
  27.                     </td> 
  28.                 </tr>
  29.  
  30.                 <tr class="dataRowIcon" id="dataRowIcon1">
  31.                     <td><div style="width:35px;"><span class="approvalIcon"><lightning:icon iconName="action:approval" size="xx-small" alternativeText="approval"/></span> <span class="rejectIcon"><lightning:icon iconName="action:close" size="xx-small" alternativeText="Reject"/></span></div></td>
  32.                     <td width="20%">SharePoint Content approval </td>
  33.                     <td width="30%"><a href="#">SharePoint Documents</a></td>
  34.                     <td width="30%">{!v.rejectDocumentMsg1}</td>
  35.                     <td width="20%">
  36.                         <button class="slds-button slds-button--success" id="approve" name="dataRowIcon1" onclick="{!c.approveAction}">Approve</button>
  37.                         <button class="slds-button slds-button--destructive" name="dataRowIcon1" onclick="{!c.rejectAction}">Reject</button>
  38.                     </td>
  39.                     <td colspan="5"></td> 
  40.                 </tr>
  41.  
  42.                 <tr class="dataRowIcon" id="dataRowIcon2">
  43.                      <td><div style="width:35px;"><span class="approvalIcon"><lightning:icon iconName="action:approval" size="xx-small" alternativeText="approval"/></span> <span class="rejectIcon"><lightning:icon iconName="action:close" size="xx-small" alternativeText="Reject"/></span></div></td>
  44.                     <td width="20%">Request sign off and Approval</td>
  45.                     <td width="30%"><a href="/resource/SamplePDF">Sign Off and Approval Documents</a></td>
  46.                     <td width="30%">{!v.rejectDocumentMsg2}</td>
  47.                     <td width="20%">
  48.                         <button class="slds-button slds-button--success" name="dataRowIcon2" onclick="{!c.approveAction}">Approve</button>
  49.                         <button class="slds-button slds-button--destructive" name="dataRowIcon2" onclick="{!c.rejectAction}">Reject</button>
  50.                     </td>
  51.                     <td colspan="5"></td> 
  52.                 </tr>
  53.  
  54.                 <tr class="dataRowIcon" id="dataRowIcon3">
  55.                     <td><div style="width:35px;"><span class="approvalIcon"><lightning:icon iconName="action:approval" size="xx-small" alternativeText="approval"/></span> <span class="rejectIcon"><lightning:icon iconName="action:close" size="xx-small" alternativeText="Reject"/></span></div></td>
  56.                     <td width="20%">Travel Document</td>
  57.                     <td width="30%"><a href="#">Travel Approval Document</a></td>
  58.                     <td width="30%">{!v.rejectDocumentMsg3}</td>
  59.                     <td width="20%">
  60.                         <button class="slds-button slds-button--success" name="dataRowIcon3" onclick="{!c.approveAction}">Approve</button>
  61.                         <button class="slds-button slds-button--destructive" name="dataRowIcon3" onclick="{!c.rejectAction}">Reject</button>
  62.                     </td>
  63.                     <td colspan="5"></td> 
  64.                 </tr>  
  65.  
  66.                 <tr class="dataRowIcon" id="dataRowIcon4">
  67.                     <td><div style="width:35px;"><span class="approvalIcon"><lightning:icon iconName="action:approval" size="xx-small" alternativeText="approval"/></span> <span class="rejectIcon"><lightning:icon iconName="action:close" size="xx-small" alternativeText="Reject"/></span></div></td>
  68.                     <td width="20%">Travel Insurance Agreements</td>
  69.                     <td width="30%"><a href="#">Travel Insurance Approval</a></td>
  70.                     <td width="30%">{!v.rejectDocumentMsg4}</td>
  71.                     <td width="20%">
  72.                         <button class="slds-button slds-button--success" name="dataRowIcon4" onclick="{!c.approveAction}">Approve</button>
  73.                         <button class="slds-button slds-button--destructive" name="dataRowIcon4" onclick="{!c.rejectAction}">Reject</button>
  74.                     </td>
  75.                     <td colspan="5"></td> 
  76.                 </tr>   
  77.  
  78.             </tbody>    
  79.         </table>
  80.  
  81.         <section id="modalFade" class="slds-modal" >
  82.             <div class="slds-modal__container">
  83.                 <header class="slds-modal__header">
  84.                     <button class="slds-button slds-modal__close slds-button--icon-inverse" name="dataRowIcon0" title="Close" onclick="{!c.closePopup}">
  85.                         <lightning:icon iconName="utility:close" variant="bare"  icon-class="slds-m-around_medium" size="small" alternativeText="close"/>
  86.                     </button>
  87.  
  88.                     <h2 class="slds-text-heading_medium slds-hyphenate">Approve/Reject Status</h2>
  89.                 </header>
  90.                 <div class="slds-modal__content slds-p-around_medium">         
  91.                     <div  class="slds-form-element">
  92.                         <label class="slds-form-element__label">Comment</label>
  93.                         <div class="slds-form-element__controller">
  94.                             <ui:inputTextArea aura:id="rejectFeedback" class="slds-textarea" value="" rows="3"/>
  95.                         </div>                                         
  96.                     </div>
  97.  
  98.                 </div>
  99.                 <footer class="slds-modal__footer">
  100.                     <button class="slds-button slds-button--destructive" name="dataRowIcon0" onclick="{!c.closePopup}">Cancel</button>
  101.                     <button class="slds-button slds-button_brand" id="reject" name="{!v.dataRowModal}" onclick="{!c.saveFeedAction}">Save</button>
  102.                 </footer>
  103.             </div>
  104.         </section>
  105.        <div id="modalBackdrop" class="slds-backdrop"></div>
  106.  
  107.  <br/><br/>
  108.    <!--Start RelatedTopics Section-->
  109. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  110.  
  111.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  112.  
  113.             <br/><br/>
  114.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β†’</span> </strong></p>
  115.             <div style="display:block; overflow:hidden;"> 
  116.                 <div style="width: 50%; float:left; display:inline-block">
  117.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  118.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  119.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  120.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  121.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  122.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  123.                     </ul>
  124.             </div>
  125.  
  126.             <div style="width: 50%; float:left; display:inline-block">
  127.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  128.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  129.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  130.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  131.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  132.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  133.                     </ul>
  134.                 </div>
  135.                <div style="clear:both;"></div> 
  136.                <br/>
  137.                 <div class="youtubeIcon">
  138.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  139.                 </div>
  140.     </div>
  141.  
  142. </div>
  143.  
  144.   <!--End RelatedTopics Section-->
  145.  
  146.     </div>
  147. </aura:component>

Create Component JavaScript Controller

Step 3:- Create Lightning Component : approveRejectCmpController.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

approveRejectCmpController.js [JavaScript Controller]

  1.   ({
  2.  
  3. 	approveAction : function(component, event, helper) {
  4. 		var thisObj = event.target.name;      
  5.         document.getElementById(thisObj).classList.remove("reject");
  6.         document.getElementById(thisObj).classList.add("approve");
  7.        //alert('thisObj ' + thisObj);
  8. 	},
  9.  
  10.     rejectAction:function(component, event, helper){
  11.          var thisObj = event.target.name;           
  12.         component.set('v.dataRowModal', thisObj);
  13.         document.getElementById('modalFade').classList.add("slds-fade-in-open");
  14.         document.getElementById('modalBackdrop').classList.add("slds-backdrop_open");
  15.     },
  16.  
  17.     closePopup:function(component, event, helper){
  18.  
  19.          document.getElementById('modalFade').classList.remove("slds-fade-in-open");
  20.          document.getElementById('modalBackdrop').classList.remove("slds-backdrop_open");
  21.     },    
  22.  
  23.     saveFeedAction:function(component, event, helper){
  24.          var thisObj = event.target.name;
  25.  
  26.         var rejectFeedback = component.find('rejectFeedback').get('v.value');        
  27.         if(thisObj == 'dataRowIcon0'){           
  28.             document.getElementById(thisObj).classList.remove("approve");        
  29.             document.getElementById(thisObj).classList.add("reject");
  30.             component.set('v.rejectDocumentMsg0',rejectFeedback);
  31.         }
  32.         if(thisObj == 'dataRowIcon1'){
  33.             document.getElementById(thisObj).classList.remove("approve");        
  34.             document.getElementById(thisObj).classList.add("reject");
  35.             component.set('v.rejectDocumentMsg1',rejectFeedback);
  36.         }
  37.  
  38.         if(thisObj == 'dataRowIcon2'){
  39.             document.getElementById(thisObj).classList.remove("approve");        
  40.             document.getElementById(thisObj).classList.add("reject");
  41.             component.set('v.rejectDocumentMsg2',rejectFeedback);
  42.         }
  43.         if(thisObj == 'dataRowIcon3'){
  44.             document.getElementById(thisObj).classList.remove("approve");        
  45.             document.getElementById(thisObj).classList.add("reject");
  46.             component.set('v.rejectDocumentMsg3',rejectFeedback);
  47.         }
  48.         if(thisObj == 'dataRowIcon4'){
  49.             document.getElementById(thisObj).classList.remove("approve");        
  50.             document.getElementById(thisObj).classList.add("reject");
  51.             component.set('v.rejectDocumentMsg4',rejectFeedback);
  52.         }
  53.  
  54.         document.getElementById('modalFade').classList.remove("slds-fade-in-open");
  55.         document.getElementById('modalBackdrop').classList.remove("slds-backdrop_open");       
  56.     },
  57.  
  58.     approveAction:function(component, event, helper){
  59.         helper.approveActionHelper(component, event, helper);
  60.     },
  61.  
  62.  
  63. })

Create Component JavaScript Helper

Step 4:- Create Lightning Component : approveRejectCmpHelper.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper

approveRejectCmpHelper.js [JavaScript Helper File]

  1.   ({
  2. 	approveActionHelper:function(component, event, helper){
  3.         var thisObj = event.target.name;      
  4.         if(thisObj == 'dataRowIcon0'){
  5.             component.set('v.rejectDocumentMsg0','Approved');
  6.         }
  7.         if(thisObj == 'dataRowIcon1'){
  8.  
  9.             component.set('v.rejectDocumentMsg1','Approved');
  10.         }
  11.  
  12.         if(thisObj == 'dataRowIcon2'){            
  13.             component.set('v.rejectDocumentMsg2','Approved');
  14.         }
  15.         if(thisObj == 'dataRowIcon3'){            
  16.             component.set('v.rejectDocumentMsg3','Approved');
  17.         }
  18.         if(thisObj == 'dataRowIcon4'){            
  19.             component.set('v.rejectDocumentMsg4','Approved');
  20.         }
  21.         document.getElementById(thisObj).classList.remove("reject");
  22.         document.getElementById(thisObj).classList.add("approve");
  23.     },
  24.  
  25. })

Create Component Style CSS

Step 5:- Create Lightning Component Style: approveRejectCmp.css

From Developer Console >> File >> New >> Lightning Component >> Component Style CSS

approveRejectCmp.css [Style CSS]

  1.   .THIS {
  2. }
  3. .THIS .dataRowIcon .approvalIcon, .THIS .dataRowIcon .rejectIcon{display:none;}
  4. .THIS .dataRowIcon .slds-fade-in-open{display:none;}
  5. .THIS .dataRowIcon .slds-backdrop_open{display:none;}
  6. .THIS .dataRowIcon.showModal .slds-fade-in-open, .THIS .dataRowIcon.showModal .slds-backdrop_open{display:block;}
  7. .THIS .dataRowIcon.approve .approvalIcon{display:inline-block;}
  8. .THIS .dataRowIcon.reject .rejectIcon{display:inline-block;}

Approve/Reject Status In Lightning Component -- w3web.net

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is a approval process in Salesforce?

An approval process is an automated process that approves records in Salesforce. When you build an approval process, you specify the steps necessary for approval. A given step can apply to all records or just records with certain attributes.

What are two final approval actions in an approval process Salesforce?

Final approval actions occur when all required approvals were obtained. A final rejection action occurs when an approver rejects the request and it moves to the final rejection state. An outbound message sends information to a designated endpoint, like an external service.

How many steps are in approval process?

The approval process ensures that all the necessary steps take place to complete any approval, while rules govern how the request is handled at various stages of the process. The following figure illustrates the five stages of any approval process.

Related Topics | You May Also Like

 
  

Our Free Courses β†’

πŸ‘‰ Get Free Course β†’

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment