• Mayank Upadhyaya 5
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 6
    Replies
Current Scenario -
XYZ customer sending email with CC people and subject name as "ABC" to salesforce and case got Created Salesforce with Subject name as "ABC".
2. Immediately CC people replying to email message using same email thread in outlook.
3. Salesforce will receive one more email with same subject name as "ABC" and new case will be created.

Expected Solution:
1. Only one case should be created under same subject name as "ABC". Even though if Salesforce receive multiple email from outlook with same subject.
2. We need to capture the Email information from cc people. (Technically, we need to capture the Email message records not case record)
3. All Email Message should comes under same Case.
Recently i got the situtaiom where all my process builders in production starts failing and error mentioned is apex cpu time limit exceeded. I am getting these errors since monday. These failures started after summer 22. I have check the user id mentioned in error log is integration user. Someone have any idea about it? What has changed in summer 22 release?
Hi Everyone , 
I have a requirement where i have to create a Quick action which should be available for specific profile.
Is it possible to restrict the quick action for a profile?

Thanks & Regards,
Mayank Upadhyaya
I have a requirement where javascript button need to convert into lightning component . in javascript button there is apex class calling in that apex class we are calling another apex which is calling another queueable apex class. please help me to implement this functionality below is the code

{!requireScript("/soap/ajax/36.0/connection.js")}
{!requireScript("/soap/ajax/36.0/apex.js")}
var mask = document.createElement('div');
var modal = document.createElement('div');
modal.textContent = 'Recreating managed opportunities...';
mask.appendChild(modal);
mask.style.position = 'fixed';
mask.style.top = '0px';
mask.style.bottom = '0px';
mask.style.left = '0px';
mask.style.right = '0px';
mask.style.background = 'rgba(0,0,0,0.5)';
mask.style.zIndex = 5000;
modal.style.width = '250px';
modal.style.marginTop = '200px';
modal.style.boxSizing = 'borderBox';
modal.style.paddingTop = '50px';
modal.style.paddingBottom = '50px';
modal.style.textAlign = 'center';
modal.style.marginLeft = 'auto';
modal.style.marginRight = 'auto';
modal.style.background = 'white';
modal.style.borderRadius = '7px';
document.body.appendChild(mask);

sforce.connection.sessionId = '{!$Api.Session_ID}';
sforce.apex.execute(
'CompositeOpportunityPrintWebservice',
'print',
{
compositeOpportunityIdStrs:['{!Opportunity.Id}']
},
{
onSuccess: function(){ location.reload() },
onFailure: function() {
document.body.removeChild(mask);
window.alert('There was an error recreating the opportunity.');
}
}
);
Here is my code,  I was not able to find the error 
-----------------Component ---------------------------------------------------

<aura:component controller="QuickOpportunityController"
    implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">

    <aura:attribute name="account" type="Account" />
    <aura:attribute name="newOpportunity" type="Opportunity"
        default="{ 'sobjectType': 'Opportunity' }" /> <!-- default to empty record -->
    
    <aura:attribute name="options" 
                  type="list" 
      default="[
                {'label': 'Discovery', 'value': 'Discovery'},
                {'label': 'Decision Maker Meeting', 'value': 'Decision Maker Meeting'},
                {'label': 'Custom Proposal', 'value': 'Custom Proposal'},
                {'label': 'Verbal Agreement', 'value': 'Verbal Agreement'},
                {'label': 'Signed Contract', 'value': 'Signed Contract'},
                 {'label': 'Closed-Installed', 'value': 'Closed-Installed'},
                 {'label': 'Closed-Lost', 'value': 'Closed-Lost'},
                {'label': 'Closed-No Decision', 'value': 'Closed-No Decision'},
                {'label': 'Closed – Duplicate', 'value': 'Closed – Duplicate'},
                {'label': 'Closed - Not Awarded', 'value': 'Closed - Not Awarded'}
               ]" 
           description="Below attribute will define picklist values if you want dynamic values then you can query that from the database and set those values"/>
     
    <aura:attribute name="options2" 
                  type="list" 
      default="[
                {'label': 'Coin and Card', 'value': 'Coin and Card'},
                {'label': 'Coin Only', 'value': 'Coin Only'},
                {'label': 'Card Only', 'value': 'Card Only'},
                 {'label': 'Change Point Only', 'value': 'Change Point Only'},
                 {'label': 'No Change or N/A', 'value': 'No Change or N/A'},
                {'label': 'Non-Vend', 'value': 'Non-Vend'},
                {'label': 'In-Unit BOLB', 'value': 'In-Unit BOLB'},
                {'label': 'In-Unit Comm Direct', 'value': 'In-Unit Comm Direct'}
               ]" 
           />
    <aura:attribute name="options3" 
                  type="list" 
      default="[               
                 {'label': 'Straight Percent', 'value': 'Straight Percent'},
                {'label': 'Sliding Scale', 'value': 'Sliding Scale'},
               {'label': 'Flat Amount', 'value': 'Flat Amount'}
               ]" 
           />
    
    <aura:attribute name="options4" 
                  type="list" 
      default="[                
                 {'label': 'None', 'value': 'None'},
                {'label': '50%', 'value': '50%'},
               {'label': '100%', 'value': '100%'}
               ]" 
           />
    
    <aura:attribute name="options1" 
                  type="list" 
      default="[
                
                 {'label': 'New', 'value': 'New'},
                {'label': 'Renewal', 'value': 'Renewal'}
               ]" 
           />
  
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <!-- Display a header with details about the account -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.account.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
            slds-truncate slds-align-left">Create New Opportunity</h1>
    </div>

    <!-- Display the new opportunity form -->
     <lightning:input aura:id="opportunityField" name="Name" label="Name"
                      value="{!v.newOpportunity.Name}" required="true"/>
     <lightning:input aura:id="opportunityField" name="RecordType" label="Record Type"
                      value="Air IRR" required="true"/>
    
     <lightning:input aura:id="opportunityField" name="Lease_Term_Months__c" label="Proposed Lease Term (mos)"
                      value="{!v.newOpportunity.Lease_Term_Months__c}" required="true"/>
    <lightning:input aura:id="opportunityField" name="CSC_Pay_Value_Recovery_Method__c" label="CSC Pay Value Recovery Method"
                      value="None" required="true"/>     
    
    <lightning:input aura:id="opportunityField" name="Capital_Date__c" label="Capital Date" type="date"
                     value="{!v.newOpportunity.Capital_Date__c}" />
    
    <lightning:input aura:id="opportunityField" name="CloseDate" label="Close Date" type="date"
                     value="{!v.newOpportunity.CloseDate}" />
    
    <lightning:combobox aura:id="opportunityField" name="Admin_Fee__c" label="Admin Fee" value="{!v.newOpportunity.Admin_Fee__c}" placeholder="Select" options= "{!v.options4}" />
    
    
    <lightning:combobox aura:id="opportunityField" name="Commission_Equation_Type__c" label="Commission Equation Type" value="{!v.newOpportunity.Commission_Equation_Type__c}" placeholder="Select" options= "{!v.options3}" />
    
     <lightning:combobox aura:id="opportunityField" name="StageName" label="Stage Name" value="{!v.newOpportunity.StageName}" placeholder="Select Stage" options= "{!v.options}" />
    
    <lightning:combobox aura:id="opportunityField" name="Type" label="Type"
                     value="{!v.newOpportunity.Type}" placeholder="Select type" required="true" options= "{!v.options1}" />
    
    <lightning:combobox aura:id="opportunityField" name="Sub_Type__c" label="Sub-Type" value="!v.newOpportunity.Sub_Type__c" placeholder="Select Sub-type" options= "{!v.options2}" />
        
    <lightning:button label="Cancel" onclick="{!c.handleCancel}" class="slds-m-top_medium" />
    <lightning:button label="Save Opportunity" onclick="{!c.handleSaveOpportunity}"
               variant="brand" class="slds-m-top_medium"/>
    
</aura:component>



-------------Controller -------------------------------------------------------------

public with sharing class QuickOpportunityController {

    @AuraEnabled
    public static Account getAccount(Id accountId) {
        // Perform isAccessible() checks here
        return [SELECT Name, BillingCity, BillingState FROM Account WHERE Id = :accountId];
    }
    
    @AuraEnabled
    public static Opportunity saveOpportunityWithAccount(Opportunity opportunity, Id accountId) {
        // Perform isAccessible() and isUpdateable() checks here
        opportunity.AccountId = accountId;
        insert opportunity;
        return opportunity;
    }

}


--------------------------------Controller JS file ----------------------------------

({
    doInit : function(component, event, helper) {

        // Prepare the action to load account record
        var action = component.get("c.getAccount");
        action.setParams({"accountId": component.get("v.recordId")});

        // Configure response handler
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
            } else {
                console.log('Problem getting account, response state: ' + state);
            }
        });
        $A.enqueueAction(action);
    },

    handleSaveOpportunity: function(component, event, helper) {
        if(helper.validateOpportunityForm(component)) {
            
            // Prepare the action to create the new opportunity
            var saveOpportunityAction = component.get("c.saveOpportunityWithAccount");
            saveOpportunityAction.setParams({
                "opportunity": component.get("v.newOpportunity"),
                "accountId": component.get("v.recordId")
            });

            // Configure the response handler for the action
            saveOpportunityAction.setCallback(this, function(response) {
                var state = response.getState();
                if(state === "SUCCESS") {

                    // Prepare a toast UI message
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title": "Opportunity Saved",
                        "message": "The new opportunity was created."
                    });

                    // Update the UI: close panel, show toast, refresh account page
                    $A.get("e.force:closeQuickAction").fire();
                    resultsToast.fire();
                    $A.get("e.force:refreshView").fire();
                }
                else if (state === "ERROR") {
                    system.debug('Problem saving opportunity, response state: ' + state);
                }
                else {
                    console.log('Unknown problem, response state: ' + state);
                }
            });

            // Send the request to create the new opportunity
            $A.enqueueAction(saveOpportunityAction);
        }
        
    },

    handleCancel: function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})


---------------------------------Helper Js -------------------------------------------

({
    validateOpportunityForm: function(component) {
        var validOpportunity = true;

        // Show error messages if required fields are blank
        var allValid = component.find('opportunityField').reduce(function (validFields, inputCmp) {
            inputCmp.showHelpMessageIfInvalid();
            return validFields && inputCmp.get('v.validity').valid;
        }, true);

        if (allValid) {
            // Verify we have an account to attach it to
            var account = component.get("v.account");
            if($A.util.isEmpty(account)) {
                validOpportunity = false;
                console.log("Quick action context doesn't have a valid account.");
            }
        }

        return(validOpportunity);
    }
})
below is the code , please let me know what i causing the issue and what we can do to resolve it.
we are getting error on line 79 when we are activating the Contract . the error is -
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contract caused an unexpected exception, contact your administrator: Contract: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors: Class.DMLBox.addErrors: line 79, column 1".



 
can anyone help me to understand how can we implement the custom meta data in Approval process?
hi  i am new in test classes , could yu please help me to write test class of below batch apex

global class CompositeOppbatchCls implements 
Database.Batchable<sObject>, Database.Stateful {
    
    string ParentOpp;

    global Database.QueryLocator start(Database.BatchableContext bc) {
       ParentOpp = 'SELECT Id, CloseDate, Status__c,Type,Sub_Type__c, Branded_As__c, is_composite__c, Lease_Term_Months__c, Proposed_DAR__c,SS_Pct_2__c,Monitoring_Fee_Air__c,Test_Fee_Air__c, Admin_Fee_Air__c,Free_Air__c,Commission_Equation_Type__c,Straight_Percent__c,Flat_Fee_Amt_Entered_Monthly__c,SS_Pct_1__c,SS_Amount_1_PM__c,Period_Payment__c,Contractual_Vend_Price_Increase__c,Forecast__c,Auto_Renewal__c,Approved_Air_Monthly_Gross_Per_Child__c,Approved_Monthly_Water_Child__c,Approved_Monthly_Air_Child__c,Coin_to_Card_Conversion__c,Approved_Monthly_Vac_Child__c,Initial_Payee__c,Opportunity_Install_Note__c,composite_opportunity__c,ChildOpportunityStage__c,Capital_Date__c ' +
                'FROM Opportunity '+ 'WHERE  Record_Type_Name__c = \'Air Composite Opportunity\' AND Status__c = \'Approved\' AND     Composite_Opp_Check__c = false AND LastModifiedDate = TODAY' ;
            System.debug('Parent Opp ' + ParentOpp);       
        return Database.getQueryLocator(ParentOpp);
        
           
    }

    global void execute(Database.BatchableContext bc, List<Opportunity> Scope){
        // process each batch of records   
    for(Opportunity r : scope){
        
        if ( r.is_composite__c){
            
            r.Composite_Opp_Check__c = true ;
        }
        
       List<Opportunity> ChildOpps = [SELECT Id, CloseDate,
                   Status__c,
                    Type,
                   Sub_Type__c,
                   Branded_As__c,
                   Lease_Term_Months__c,
                   Proposed_DAR__c,
                   Monitoring_Fee_Air__c,
                   Test_Fee_Air__c,
                   Admin_Fee_Air__c,
                   Free_Air__c,
                   Commission_Equation_Type__c,
                   Straight_Percent__c,
                   Flat_Fee_Amt_Entered_Monthly__c,
                   SS_Pct_1__c,
                   SS_Pct_2__c,                  
                   SS_Amount_1_PM__c,
                   Contractual_Vend_Price_Increase__c,                  
                   Period_Payment__c,
                   Forecast__c,
                   Auto_Renewal__c,
                   Coin_to_Card_Conversion__c,
                   Initial_Payee__c,
                   Opportunity_Install_Note__c,
                   composite_opportunity__c,
                   StageName,  
                   Approved_Monthly_Vac_Per_Child__c,
                   Approved_Monthly_Air_Per_Child__c,
                   Approved_Monthly_Water_Per_Child__c,
                   Approved_Monthly_Gross_PM_Per_Child__c,                   
                   Capital_Date__c FROM Opportunity WHERE composite_opportunity__c =:r.Id] ;
        
        System.debug('Child Opps ' + ChildOpps);
        
      for(Opportunity o : ChildOpps){ 
          
         o.CloseDate = r.CloseDate;         
         o.Initial_Payee__c = r.Initial_Payee__c;
         o.Opportunity_Install_Note__c = r.Opportunity_Install_Note__c;
         o.Auto_Renewal__c = r.Auto_Renewal__c;
         o.SS_Amount_1_PM__c = r.SS_Amount_1_PM__c;
         o.Period_Payment__c = r.Period_Payment__c;
         o.Contractual_Vend_Price_Increase__c = r.Contractual_Vend_Price_Increase__c;
         o.Forecast__c = r.Forecast__c;
         o.Coin_to_Card_Conversion__c = r.Coin_to_Card_Conversion__c;
         o.Free_Air__c = r.Free_Air__c;
         o.Admin_Fee_Air__c = r.Admin_Fee_Air__c;
         o.Test_Fee_Air__c = r.Test_Fee_Air__c;
         o.Commission_Equation_Type__c = r.Commission_Equation_Type__c;
         o.Monitoring_Fee_Air__c = r.Monitoring_Fee_Air__c;
         o.Proposed_DAR__c = r.Proposed_DAR__c;
         o.Type = r.Type;
         o.Sub_Type__c = r.Sub_Type__c;
         o.SS_Pct_1__c = r.SS_Pct_1__c;
         o.SS_Pct_2__c = r.SS_Pct_2__c;
         o.Status__c = r.Status__c;
         o.Branded_As__c = r.Branded_As__c;
         o.Straight_Percent__c = r.Straight_Percent__c;
         o.Flat_Fee_Amt_Entered_Monthly__c = r.Flat_Fee_Amt_Entered_Monthly__c;
         o.Capital_Date__c = r.Capital_Date__c;
         o.StageName = r.ChildOpportunityStage__c;
         o.Lease_Term_Months__c = r.Lease_Term_Months__c;
         o.Approved_Monthly_Vac_Per_Child__c = r.Approved_Monthly_Vac_Child__c; 
         o.Approved_Monthly_Air_Per_Child__c = r.Approved_Monthly_Air_Child__c;    
         o.Approved_Monthly_Water_Per_Child__c =  r.Approved_Monthly_Water_Child__c;
         o.Approved_Monthly_Gross_PM_Per_Child__c = r.Approved_Air_Monthly_Gross_Per_Child__c;  
          
        }  
             Update ChildOpps;
           System.debug('Child Opps ' + ChildOpps);
     }
     Update scope;        
    }    

    global void finish(Database.BatchableContext bc){
        //  System.debug(recordsProcessed + ' records processed.');
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
                            JobItemsProcessed,
                            TotalJobItems, CreatedBy.Email
                            FROM AsyncApexJob
                            WHERE Id = :bc.getJobId()];
          
    }    
}
Hi everyone i  am new in apex . I have a requirement Batch where i need to Update all opportunity child record from Parent child record from batch apex . Parent opportunity and child opportunity have looke up relationship and look up field is composite_opportunity__c
i have condition where child records should be updated with the latest field values of Parent opportunity and batch apex should be run daily. These are below fields which need to update on child opportunity 

Proposed_Net_PMPM_Revised__c, Proposed_GPMGIPM__c, Certified_Equipment__c, Total_Machines_Pockets__c, IncentivePayments__c, Betterments__c, VentingPlumbing__c, Wiring__c, Other_Capital__c, Capital_Total_Revised__c, Prev_Net_PMPM__c, IRR_2014__c, Lease_Term_Months__c, Monthly_Cashflow_VCI__c, Proposed_Gross_PMPM_Include_Inc__c, Average_Vend_Price__c, Midterm_Vend_Increase_Percentage__c, Prop_Gross_Monthly_Revenue__c, Scoring_Model_Total_Points__c, Proposed_Net_PMPM_VCI__c, Equipment_Total__c, Status__c, Capital_Coverage__c, Payback_Percentage__c, NRPM_Percentage__c, Commission_Percentage__c, Certified_Equipment_Percentage__c, Non_Equipment_Percentage__c, VCI__c, NPV_Cashflow_VCI__c, Months_Remaining_Existing_Contract__c, Override_Months_Remaining_New__c, Existing_Equipment_Count__c

Please let me know if anyone have sample code for this logic.

Thanks
Here is my code,  I was not able to find the error 
-----------------Component ---------------------------------------------------

<aura:component controller="QuickOpportunityController"
    implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">

    <aura:attribute name="account" type="Account" />
    <aura:attribute name="newOpportunity" type="Opportunity"
        default="{ 'sobjectType': 'Opportunity' }" /> <!-- default to empty record -->
    
    <aura:attribute name="options" 
                  type="list" 
      default="[
                {'label': 'Discovery', 'value': 'Discovery'},
                {'label': 'Decision Maker Meeting', 'value': 'Decision Maker Meeting'},
                {'label': 'Custom Proposal', 'value': 'Custom Proposal'},
                {'label': 'Verbal Agreement', 'value': 'Verbal Agreement'},
                {'label': 'Signed Contract', 'value': 'Signed Contract'},
                 {'label': 'Closed-Installed', 'value': 'Closed-Installed'},
                 {'label': 'Closed-Lost', 'value': 'Closed-Lost'},
                {'label': 'Closed-No Decision', 'value': 'Closed-No Decision'},
                {'label': 'Closed – Duplicate', 'value': 'Closed – Duplicate'},
                {'label': 'Closed - Not Awarded', 'value': 'Closed - Not Awarded'}
               ]" 
           description="Below attribute will define picklist values if you want dynamic values then you can query that from the database and set those values"/>
     
    <aura:attribute name="options2" 
                  type="list" 
      default="[
                {'label': 'Coin and Card', 'value': 'Coin and Card'},
                {'label': 'Coin Only', 'value': 'Coin Only'},
                {'label': 'Card Only', 'value': 'Card Only'},
                 {'label': 'Change Point Only', 'value': 'Change Point Only'},
                 {'label': 'No Change or N/A', 'value': 'No Change or N/A'},
                {'label': 'Non-Vend', 'value': 'Non-Vend'},
                {'label': 'In-Unit BOLB', 'value': 'In-Unit BOLB'},
                {'label': 'In-Unit Comm Direct', 'value': 'In-Unit Comm Direct'}
               ]" 
           />
    <aura:attribute name="options3" 
                  type="list" 
      default="[               
                 {'label': 'Straight Percent', 'value': 'Straight Percent'},
                {'label': 'Sliding Scale', 'value': 'Sliding Scale'},
               {'label': 'Flat Amount', 'value': 'Flat Amount'}
               ]" 
           />
    
    <aura:attribute name="options4" 
                  type="list" 
      default="[                
                 {'label': 'None', 'value': 'None'},
                {'label': '50%', 'value': '50%'},
               {'label': '100%', 'value': '100%'}
               ]" 
           />
    
    <aura:attribute name="options1" 
                  type="list" 
      default="[
                
                 {'label': 'New', 'value': 'New'},
                {'label': 'Renewal', 'value': 'Renewal'}
               ]" 
           />
  
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <!-- Display a header with details about the account -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.account.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
            slds-truncate slds-align-left">Create New Opportunity</h1>
    </div>

    <!-- Display the new opportunity form -->
     <lightning:input aura:id="opportunityField" name="Name" label="Name"
                      value="{!v.newOpportunity.Name}" required="true"/>
     <lightning:input aura:id="opportunityField" name="RecordType" label="Record Type"
                      value="Air IRR" required="true"/>
    
     <lightning:input aura:id="opportunityField" name="Lease_Term_Months__c" label="Proposed Lease Term (mos)"
                      value="{!v.newOpportunity.Lease_Term_Months__c}" required="true"/>
    <lightning:input aura:id="opportunityField" name="CSC_Pay_Value_Recovery_Method__c" label="CSC Pay Value Recovery Method"
                      value="None" required="true"/>     
    
    <lightning:input aura:id="opportunityField" name="Capital_Date__c" label="Capital Date" type="date"
                     value="{!v.newOpportunity.Capital_Date__c}" />
    
    <lightning:input aura:id="opportunityField" name="CloseDate" label="Close Date" type="date"
                     value="{!v.newOpportunity.CloseDate}" />
    
    <lightning:combobox aura:id="opportunityField" name="Admin_Fee__c" label="Admin Fee" value="{!v.newOpportunity.Admin_Fee__c}" placeholder="Select" options= "{!v.options4}" />
    
    
    <lightning:combobox aura:id="opportunityField" name="Commission_Equation_Type__c" label="Commission Equation Type" value="{!v.newOpportunity.Commission_Equation_Type__c}" placeholder="Select" options= "{!v.options3}" />
    
     <lightning:combobox aura:id="opportunityField" name="StageName" label="Stage Name" value="{!v.newOpportunity.StageName}" placeholder="Select Stage" options= "{!v.options}" />
    
    <lightning:combobox aura:id="opportunityField" name="Type" label="Type"
                     value="{!v.newOpportunity.Type}" placeholder="Select type" required="true" options= "{!v.options1}" />
    
    <lightning:combobox aura:id="opportunityField" name="Sub_Type__c" label="Sub-Type" value="!v.newOpportunity.Sub_Type__c" placeholder="Select Sub-type" options= "{!v.options2}" />
        
    <lightning:button label="Cancel" onclick="{!c.handleCancel}" class="slds-m-top_medium" />
    <lightning:button label="Save Opportunity" onclick="{!c.handleSaveOpportunity}"
               variant="brand" class="slds-m-top_medium"/>
    
</aura:component>



-------------Controller -------------------------------------------------------------

public with sharing class QuickOpportunityController {

    @AuraEnabled
    public static Account getAccount(Id accountId) {
        // Perform isAccessible() checks here
        return [SELECT Name, BillingCity, BillingState FROM Account WHERE Id = :accountId];
    }
    
    @AuraEnabled
    public static Opportunity saveOpportunityWithAccount(Opportunity opportunity, Id accountId) {
        // Perform isAccessible() and isUpdateable() checks here
        opportunity.AccountId = accountId;
        insert opportunity;
        return opportunity;
    }

}


--------------------------------Controller JS file ----------------------------------

({
    doInit : function(component, event, helper) {

        // Prepare the action to load account record
        var action = component.get("c.getAccount");
        action.setParams({"accountId": component.get("v.recordId")});

        // Configure response handler
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
            } else {
                console.log('Problem getting account, response state: ' + state);
            }
        });
        $A.enqueueAction(action);
    },

    handleSaveOpportunity: function(component, event, helper) {
        if(helper.validateOpportunityForm(component)) {
            
            // Prepare the action to create the new opportunity
            var saveOpportunityAction = component.get("c.saveOpportunityWithAccount");
            saveOpportunityAction.setParams({
                "opportunity": component.get("v.newOpportunity"),
                "accountId": component.get("v.recordId")
            });

            // Configure the response handler for the action
            saveOpportunityAction.setCallback(this, function(response) {
                var state = response.getState();
                if(state === "SUCCESS") {

                    // Prepare a toast UI message
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title": "Opportunity Saved",
                        "message": "The new opportunity was created."
                    });

                    // Update the UI: close panel, show toast, refresh account page
                    $A.get("e.force:closeQuickAction").fire();
                    resultsToast.fire();
                    $A.get("e.force:refreshView").fire();
                }
                else if (state === "ERROR") {
                    system.debug('Problem saving opportunity, response state: ' + state);
                }
                else {
                    console.log('Unknown problem, response state: ' + state);
                }
            });

            // Send the request to create the new opportunity
            $A.enqueueAction(saveOpportunityAction);
        }
        
    },

    handleCancel: function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})


---------------------------------Helper Js -------------------------------------------

({
    validateOpportunityForm: function(component) {
        var validOpportunity = true;

        // Show error messages if required fields are blank
        var allValid = component.find('opportunityField').reduce(function (validFields, inputCmp) {
            inputCmp.showHelpMessageIfInvalid();
            return validFields && inputCmp.get('v.validity').valid;
        }, true);

        if (allValid) {
            // Verify we have an account to attach it to
            var account = component.get("v.account");
            if($A.util.isEmpty(account)) {
                validOpportunity = false;
                console.log("Quick action context doesn't have a valid account.");
            }
        }

        return(validOpportunity);
    }
})
Here is my code,  I was not able to find the error 
-----------------Component ---------------------------------------------------

<aura:component controller="QuickOpportunityController"
    implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">

    <aura:attribute name="account" type="Account" />
    <aura:attribute name="newOpportunity" type="Opportunity"
        default="{ 'sobjectType': 'Opportunity' }" /> <!-- default to empty record -->
    
    <aura:attribute name="options" 
                  type="list" 
      default="[
                {'label': 'Discovery', 'value': 'Discovery'},
                {'label': 'Decision Maker Meeting', 'value': 'Decision Maker Meeting'},
                {'label': 'Custom Proposal', 'value': 'Custom Proposal'},
                {'label': 'Verbal Agreement', 'value': 'Verbal Agreement'},
                {'label': 'Signed Contract', 'value': 'Signed Contract'},
                 {'label': 'Closed-Installed', 'value': 'Closed-Installed'},
                 {'label': 'Closed-Lost', 'value': 'Closed-Lost'},
                {'label': 'Closed-No Decision', 'value': 'Closed-No Decision'},
                {'label': 'Closed – Duplicate', 'value': 'Closed – Duplicate'},
                {'label': 'Closed - Not Awarded', 'value': 'Closed - Not Awarded'}
               ]" 
           description="Below attribute will define picklist values if you want dynamic values then you can query that from the database and set those values"/>
     
    <aura:attribute name="options2" 
                  type="list" 
      default="[
                {'label': 'Coin and Card', 'value': 'Coin and Card'},
                {'label': 'Coin Only', 'value': 'Coin Only'},
                {'label': 'Card Only', 'value': 'Card Only'},
                 {'label': 'Change Point Only', 'value': 'Change Point Only'},
                 {'label': 'No Change or N/A', 'value': 'No Change or N/A'},
                {'label': 'Non-Vend', 'value': 'Non-Vend'},
                {'label': 'In-Unit BOLB', 'value': 'In-Unit BOLB'},
                {'label': 'In-Unit Comm Direct', 'value': 'In-Unit Comm Direct'}
               ]" 
           />
    <aura:attribute name="options3" 
                  type="list" 
      default="[               
                 {'label': 'Straight Percent', 'value': 'Straight Percent'},
                {'label': 'Sliding Scale', 'value': 'Sliding Scale'},
               {'label': 'Flat Amount', 'value': 'Flat Amount'}
               ]" 
           />
    
    <aura:attribute name="options4" 
                  type="list" 
      default="[                
                 {'label': 'None', 'value': 'None'},
                {'label': '50%', 'value': '50%'},
               {'label': '100%', 'value': '100%'}
               ]" 
           />
    
    <aura:attribute name="options1" 
                  type="list" 
      default="[
                
                 {'label': 'New', 'value': 'New'},
                {'label': 'Renewal', 'value': 'Renewal'}
               ]" 
           />
  
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <!-- Display a header with details about the account -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.account.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
            slds-truncate slds-align-left">Create New Opportunity</h1>
    </div>

    <!-- Display the new opportunity form -->
     <lightning:input aura:id="opportunityField" name="Name" label="Name"
                      value="{!v.newOpportunity.Name}" required="true"/>
     <lightning:input aura:id="opportunityField" name="RecordType" label="Record Type"
                      value="Air IRR" required="true"/>
    
     <lightning:input aura:id="opportunityField" name="Lease_Term_Months__c" label="Proposed Lease Term (mos)"
                      value="{!v.newOpportunity.Lease_Term_Months__c}" required="true"/>
    <lightning:input aura:id="opportunityField" name="CSC_Pay_Value_Recovery_Method__c" label="CSC Pay Value Recovery Method"
                      value="None" required="true"/>     
    
    <lightning:input aura:id="opportunityField" name="Capital_Date__c" label="Capital Date" type="date"
                     value="{!v.newOpportunity.Capital_Date__c}" />
    
    <lightning:input aura:id="opportunityField" name="CloseDate" label="Close Date" type="date"
                     value="{!v.newOpportunity.CloseDate}" />
    
    <lightning:combobox aura:id="opportunityField" name="Admin_Fee__c" label="Admin Fee" value="{!v.newOpportunity.Admin_Fee__c}" placeholder="Select" options= "{!v.options4}" />
    
    
    <lightning:combobox aura:id="opportunityField" name="Commission_Equation_Type__c" label="Commission Equation Type" value="{!v.newOpportunity.Commission_Equation_Type__c}" placeholder="Select" options= "{!v.options3}" />
    
     <lightning:combobox aura:id="opportunityField" name="StageName" label="Stage Name" value="{!v.newOpportunity.StageName}" placeholder="Select Stage" options= "{!v.options}" />
    
    <lightning:combobox aura:id="opportunityField" name="Type" label="Type"
                     value="{!v.newOpportunity.Type}" placeholder="Select type" required="true" options= "{!v.options1}" />
    
    <lightning:combobox aura:id="opportunityField" name="Sub_Type__c" label="Sub-Type" value="!v.newOpportunity.Sub_Type__c" placeholder="Select Sub-type" options= "{!v.options2}" />
        
    <lightning:button label="Cancel" onclick="{!c.handleCancel}" class="slds-m-top_medium" />
    <lightning:button label="Save Opportunity" onclick="{!c.handleSaveOpportunity}"
               variant="brand" class="slds-m-top_medium"/>
    
</aura:component>



-------------Controller -------------------------------------------------------------

public with sharing class QuickOpportunityController {

    @AuraEnabled
    public static Account getAccount(Id accountId) {
        // Perform isAccessible() checks here
        return [SELECT Name, BillingCity, BillingState FROM Account WHERE Id = :accountId];
    }
    
    @AuraEnabled
    public static Opportunity saveOpportunityWithAccount(Opportunity opportunity, Id accountId) {
        // Perform isAccessible() and isUpdateable() checks here
        opportunity.AccountId = accountId;
        insert opportunity;
        return opportunity;
    }

}


--------------------------------Controller JS file ----------------------------------

({
    doInit : function(component, event, helper) {

        // Prepare the action to load account record
        var action = component.get("c.getAccount");
        action.setParams({"accountId": component.get("v.recordId")});

        // Configure response handler
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
            } else {
                console.log('Problem getting account, response state: ' + state);
            }
        });
        $A.enqueueAction(action);
    },

    handleSaveOpportunity: function(component, event, helper) {
        if(helper.validateOpportunityForm(component)) {
            
            // Prepare the action to create the new opportunity
            var saveOpportunityAction = component.get("c.saveOpportunityWithAccount");
            saveOpportunityAction.setParams({
                "opportunity": component.get("v.newOpportunity"),
                "accountId": component.get("v.recordId")
            });

            // Configure the response handler for the action
            saveOpportunityAction.setCallback(this, function(response) {
                var state = response.getState();
                if(state === "SUCCESS") {

                    // Prepare a toast UI message
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title": "Opportunity Saved",
                        "message": "The new opportunity was created."
                    });

                    // Update the UI: close panel, show toast, refresh account page
                    $A.get("e.force:closeQuickAction").fire();
                    resultsToast.fire();
                    $A.get("e.force:refreshView").fire();
                }
                else if (state === "ERROR") {
                    system.debug('Problem saving opportunity, response state: ' + state);
                }
                else {
                    console.log('Unknown problem, response state: ' + state);
                }
            });

            // Send the request to create the new opportunity
            $A.enqueueAction(saveOpportunityAction);
        }
        
    },

    handleCancel: function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})


---------------------------------Helper Js -------------------------------------------

({
    validateOpportunityForm: function(component) {
        var validOpportunity = true;

        // Show error messages if required fields are blank
        var allValid = component.find('opportunityField').reduce(function (validFields, inputCmp) {
            inputCmp.showHelpMessageIfInvalid();
            return validFields && inputCmp.get('v.validity').valid;
        }, true);

        if (allValid) {
            // Verify we have an account to attach it to
            var account = component.get("v.account");
            if($A.util.isEmpty(account)) {
                validOpportunity = false;
                console.log("Quick action context doesn't have a valid account.");
            }
        }

        return(validOpportunity);
    }
})
below is the code , please let me know what i causing the issue and what we can do to resolve it.
we are getting error on line 79 when we are activating the Contract . the error is -
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contract caused an unexpected exception, contact your administrator: Contract: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors: Class.DMLBox.addErrors: line 79, column 1".



 
can anyone help me to understand how can we implement the custom meta data in Approval process?
hi  i am new in test classes , could yu please help me to write test class of below batch apex

global class CompositeOppbatchCls implements 
Database.Batchable<sObject>, Database.Stateful {
    
    string ParentOpp;

    global Database.QueryLocator start(Database.BatchableContext bc) {
       ParentOpp = 'SELECT Id, CloseDate, Status__c,Type,Sub_Type__c, Branded_As__c, is_composite__c, Lease_Term_Months__c, Proposed_DAR__c,SS_Pct_2__c,Monitoring_Fee_Air__c,Test_Fee_Air__c, Admin_Fee_Air__c,Free_Air__c,Commission_Equation_Type__c,Straight_Percent__c,Flat_Fee_Amt_Entered_Monthly__c,SS_Pct_1__c,SS_Amount_1_PM__c,Period_Payment__c,Contractual_Vend_Price_Increase__c,Forecast__c,Auto_Renewal__c,Approved_Air_Monthly_Gross_Per_Child__c,Approved_Monthly_Water_Child__c,Approved_Monthly_Air_Child__c,Coin_to_Card_Conversion__c,Approved_Monthly_Vac_Child__c,Initial_Payee__c,Opportunity_Install_Note__c,composite_opportunity__c,ChildOpportunityStage__c,Capital_Date__c ' +
                'FROM Opportunity '+ 'WHERE  Record_Type_Name__c = \'Air Composite Opportunity\' AND Status__c = \'Approved\' AND     Composite_Opp_Check__c = false AND LastModifiedDate = TODAY' ;
            System.debug('Parent Opp ' + ParentOpp);       
        return Database.getQueryLocator(ParentOpp);
        
           
    }

    global void execute(Database.BatchableContext bc, List<Opportunity> Scope){
        // process each batch of records   
    for(Opportunity r : scope){
        
        if ( r.is_composite__c){
            
            r.Composite_Opp_Check__c = true ;
        }
        
       List<Opportunity> ChildOpps = [SELECT Id, CloseDate,
                   Status__c,
                    Type,
                   Sub_Type__c,
                   Branded_As__c,
                   Lease_Term_Months__c,
                   Proposed_DAR__c,
                   Monitoring_Fee_Air__c,
                   Test_Fee_Air__c,
                   Admin_Fee_Air__c,
                   Free_Air__c,
                   Commission_Equation_Type__c,
                   Straight_Percent__c,
                   Flat_Fee_Amt_Entered_Monthly__c,
                   SS_Pct_1__c,
                   SS_Pct_2__c,                  
                   SS_Amount_1_PM__c,
                   Contractual_Vend_Price_Increase__c,                  
                   Period_Payment__c,
                   Forecast__c,
                   Auto_Renewal__c,
                   Coin_to_Card_Conversion__c,
                   Initial_Payee__c,
                   Opportunity_Install_Note__c,
                   composite_opportunity__c,
                   StageName,  
                   Approved_Monthly_Vac_Per_Child__c,
                   Approved_Monthly_Air_Per_Child__c,
                   Approved_Monthly_Water_Per_Child__c,
                   Approved_Monthly_Gross_PM_Per_Child__c,                   
                   Capital_Date__c FROM Opportunity WHERE composite_opportunity__c =:r.Id] ;
        
        System.debug('Child Opps ' + ChildOpps);
        
      for(Opportunity o : ChildOpps){ 
          
         o.CloseDate = r.CloseDate;         
         o.Initial_Payee__c = r.Initial_Payee__c;
         o.Opportunity_Install_Note__c = r.Opportunity_Install_Note__c;
         o.Auto_Renewal__c = r.Auto_Renewal__c;
         o.SS_Amount_1_PM__c = r.SS_Amount_1_PM__c;
         o.Period_Payment__c = r.Period_Payment__c;
         o.Contractual_Vend_Price_Increase__c = r.Contractual_Vend_Price_Increase__c;
         o.Forecast__c = r.Forecast__c;
         o.Coin_to_Card_Conversion__c = r.Coin_to_Card_Conversion__c;
         o.Free_Air__c = r.Free_Air__c;
         o.Admin_Fee_Air__c = r.Admin_Fee_Air__c;
         o.Test_Fee_Air__c = r.Test_Fee_Air__c;
         o.Commission_Equation_Type__c = r.Commission_Equation_Type__c;
         o.Monitoring_Fee_Air__c = r.Monitoring_Fee_Air__c;
         o.Proposed_DAR__c = r.Proposed_DAR__c;
         o.Type = r.Type;
         o.Sub_Type__c = r.Sub_Type__c;
         o.SS_Pct_1__c = r.SS_Pct_1__c;
         o.SS_Pct_2__c = r.SS_Pct_2__c;
         o.Status__c = r.Status__c;
         o.Branded_As__c = r.Branded_As__c;
         o.Straight_Percent__c = r.Straight_Percent__c;
         o.Flat_Fee_Amt_Entered_Monthly__c = r.Flat_Fee_Amt_Entered_Monthly__c;
         o.Capital_Date__c = r.Capital_Date__c;
         o.StageName = r.ChildOpportunityStage__c;
         o.Lease_Term_Months__c = r.Lease_Term_Months__c;
         o.Approved_Monthly_Vac_Per_Child__c = r.Approved_Monthly_Vac_Child__c; 
         o.Approved_Monthly_Air_Per_Child__c = r.Approved_Monthly_Air_Child__c;    
         o.Approved_Monthly_Water_Per_Child__c =  r.Approved_Monthly_Water_Child__c;
         o.Approved_Monthly_Gross_PM_Per_Child__c = r.Approved_Air_Monthly_Gross_Per_Child__c;  
          
        }  
             Update ChildOpps;
           System.debug('Child Opps ' + ChildOpps);
     }
     Update scope;        
    }    

    global void finish(Database.BatchableContext bc){
        //  System.debug(recordsProcessed + ' records processed.');
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
                            JobItemsProcessed,
                            TotalJobItems, CreatedBy.Email
                            FROM AsyncApexJob
                            WHERE Id = :bc.getJobId()];
          
    }    
}