function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sarita Pa 3Sarita Pa 3 

Use Action on standard Object with out apex controller

Good Morning.
Would like to know if we can use Action attributes for standard objects.
What ever the documentation i see everywhere actions are being retrieved from custom controller only.
Example of what I am trying and what errors I am getting is b
<aura:component implements="force:lightningQuickAction,force:hasRecordId">
 <aura:attribute name="record" type="Opportunity"/> (This is the standard Object)
   <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>

<force:recordData aura:id="record"
      recordId="{!v.recordId}"
      fields="AccountId"
      targetFields="{!v.simpleRecord}"
      targetError="{!v.recordError}"
      recordUpdated="{!c.handleRecordUpdated}"
      />
    
    <h1>
    {!v.simpleRecord.AccountId}
    </h1>

</aura:component>

controller:
({
    handleRecordUpdated: function (component, event) {
      var action = component.get("v.record"); (This is tied to the opportunity object) 
    // Here is the issue what I am facing
//     when I  try to set some parameters as
action.setParams() --> Getting errors set params method is not defined.
    }
})
Please correct me if I am missing any thing and let me know if there is any example of using standard object with action attribute.

Thanks for your help in advance
 
Raj VakatiRaj Vakati
Try this code
 
<aura:component implements="force:lightningQuickAction,force:hasRecordId">
    <aura:attribute name="record" type="Opportunity"/>
    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    
    <force:recordData aura:id="record"
                      recordId="{!v.recordId}"
                      fields="AccountId"
                      mode="EDIT"
                      targetFields="{!v.simpleRecord}"
                      targetError="{!v.recordError}"
                      recordUpdated="{!c.handleRecordUpdated}"
                      
                      />
    
    <h1>
        {!v.simpleRecord.AccountId}
    </h1>
    
    <div class="Record Details">
        
        <lightning:card iconName="action:edit" title="Edit Account">
            
            <div class="slds-p-horizontal--small">
                
                <lightning:inputField label="Account Name" value="{!v.simpleRecord.AccountId}"/>
                
                <br/>
                
                <lightning:button label="Update Account" variant="brand" onclick="{!c.handleRecordUpdated}" />
                
            </div>
            
        </lightning:card>
        
    </div>
    
    
</aura:component>
 
({
    handleRecordUpdated: function(component, event, helper) {
        component.find("record").saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                console.log("Save completed successfully.");
            } else if (saveResult.state === "INCOMPLETE") {
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                console.log('Problem saving record, error: ' + 
                            JSON.stringify(saveResult.error));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }));}
})



https://developer.salesforce.com/docs/atlas.en-us.214.0.lightning.meta/lightning/data_service_save_record.htm

https://developer.salesforce.com/docs/atlas.en-us.214.0.lightning.meta/lightning/data_service_saverecordresult.htm
https://developer.salesforce.com/docs/atlas.en-us.214.0.lightning.meta/lightning/data_service_save_record.htm
https://trailhead.salesforce.com/en/modules/lightning_data_service/units/lightning_data_service_manipulate_records