You are here:
Create Lightning Component for Update Contracts Action Button
To configure a update contracts action button, the system admin must create a lightning component that will call the connected API called Update Contracts.
- Create an Apex class.
- Click File | New | Apex Class.
- Enter a name for the apex class. For example, UpdateContract.
- Click OK.
- Paste the code.
public class UpdateContractController { @AuraEnabled public static List<String> getUpdatedRecord(String sourceRecordId, Boolean autoDocgen) { ConnectApi.ContractInputRepresentation objInput = new ConnectApi.ContractInputRepresentation(); objInput.sourceObjectId = sourceRecordId; objInput.isAutoDocgenRequired = autoDocgen; ConnectApi.ContractOutputRepresentation objOutput = ConnectApi.Clm.updateContract(objInput); List<String> contractData = new List<String>(); contractData.add(objOutput.data[0]); return contractData; } } - Save your changes.
- Open the developer console.
- Create a lightning component:
- Click File | New | Lightning Component.
- Enter a name for the lightning component.For example, <UpdateContractFromCustomObject>.
- Select Lightning Quick Action.
- Click Submit.The lightning component class page opens.
- Paste the code.
<aura:component controller="UpdateContractController" implements="force:lightningQuickAction,force:hasRecordId"> <aura:html tag="style"> .modal-body.spinnerHeight{ height: 25% } </aura:html> <aura:handler name="init" value="{!this}" action="{!c.onInit}"/> <aura:attribute name="recordId" type="String" description="stores the record id"/> <lightning:navigation aura:id="navLink"/> <aura:attribute name="Spinner" type="boolean" default="true"/> <aura:if isTrue="{!v.Spinner}"> <div style="height:6rem;position:relative"> <lightning:spinner variant="brand" alternativeText="Loading..." size="large"/> </div> </aura:if> </aura:component> - Save your changes.
- Create a controller.
- Click CONTROLLER.
- Paste the code.
({ onInit: function (cmp, event, helper) { var updateContractAction = cmp.get("c.getUpdatedRecord"); cmp.set("v.Spinner", true); updateContractAction.setParams({ sourceRecordId : cmp.get("v.recordId"), autoDocgen : "true" }); updateContractAction.setCallback(this, function(result) { var state = result.getState(); var response; if (state === 'SUCCESS') { cmp.set("v.Spinner", false); response = result.getReturnValue(); $A.get("e.force:showToast").setParams({ mode: 'dismissible', type: "success", message: "Contracts Updated Succesfully" }).fire(); }else{ cmp.set("v.Spinner", false); $A.get("e.force:showToast").setParams({ mode: 'dismissible', type: "error", message: result.getError() && result.getError()[0] && result.getError()[0].message ? result.getError()[0].message :"Error while updating contracts", duration: 10000, }).fire(); } $A.get("e.force:closeQuickAction").fire(); }); $A.enqueueAction(updateContractAction); } }) - Save your changes.

