+ Start a Discussion
Nevin O'Regan 3Nevin O'Regan 3 

Custom Lightning Button Help

Hi guys, 

I'm looking to try and build a custom button which creates a new record and also update a value in another record.
The object in question is a custom object called Payment. The purpose of this button is to allow users replace a payment with another payment. So if a user clicks on this button from within a payment record they will input the field values of the new payment record and the status value of the payment record from which the action was triggered will update to 'Replaced'. 
Is this possible through Quick Actions or Buttons and could anyone help me with it?
Best Answer chosen by Nevin O'Regan 3
Ajeet28augAjeet28aug
Hi Nevin,

Based on the above scenario, we can simply use Flows. 

1. Create a new Flow
2. Create a variable called: recordId
3. Drag a screen component and insert fields
4. Use the 'Create Record' Element to create the record
5. Use the 'Update Record' element to update the record, where Id = recordId

Let me know if the above helps

Regards
-Ajeet Jain
SalesforceGig (https://salesforcegig.com)

All Answers

Ajeet28augAjeet28aug
Hi Nevin,

With a single button, you can either create a new record or update a record. I would suggest you create a lightning component, that will handle both situations.

Let me know if you need any further help.

Regards
-Ajeet Jain
SalesforceGig (https://Salesforcegig.com)
 
Nevin O'Regan 3Nevin O'Regan 3
Hi Ajeet,

I'm new to building lightning components so any help you could give me would be great. 
Ajeet28augAjeet28aug

Hi Nevin,

Step1: Create lightning component using the force:lightningQuickAction & force:hasRecordId interface.[https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation]
Step2: Implement Lightning:recordForm to create the record [https://developer.salesforce.com/docs/component-library/bundle/lightning:recordForm/documentation]
Step3: Implement another lightning:recordForm for the original record in the read-only mode. 
Step4: After the successful creation of the record in step2, update the value for the original record & save it. 

Let me know if the above helps, or if you need further help, just drop me Hi on skype: salesforcegig, I can walk you through the process. 

Regards
-Ajeet Jain
SalesforceGig (https://salesforcegig.com)

Nevin O'Regan 3Nevin O'Regan 3
Hi Ajeet,

Thanks for this. I will try and follow these steps first and if I'm running into difficulty it would be great if we could get on a call 
Nevin O'Regan 3Nevin O'Regan 3
Hi Ajeet,

This solution seems to be actually displaying a full component which includes all of the field attributes in it. I'm only looking for a simple button so that when a user clicks on it they are redirected to a 'New Payment' record screen where they input the data and save it. The status of the payment record where this was initiated is then updated to 'Replaced'. So basically I am trying to only display a button on the payment record called 'Replaced'.
 
Ajeet28augAjeet28aug
Hi Nevin,

Based on the above scenario, we can simply use Flows. 

1. Create a new Flow
2. Create a variable called: recordId
3. Drag a screen component and insert fields
4. Use the 'Create Record' Element to create the record
5. Use the 'Update Record' element to update the record, where Id = recordId

Let me know if the above helps

Regards
-Ajeet Jain
SalesforceGig (https://salesforcegig.com)
This was selected as the best answer
Nevin O'Regan 3Nevin O'Regan 3
Yes I was thinking a flow might also work for this. Let me look into it. thanks Ajeet