You need to sign in to do that
Don't have an account?
Baz Denson
Future Method cannot be called from future or batch method.
I have 2 future calls. The first creates a record in our accounting software via call out.
I then use another future method to create an invoice in the accounting software and pass it the customer ID returned from the first future method.
I have created 2 seperate apex classes. Both are invocable processes. When a status changes on the opportunity I use process builder to fire the first call to create the customer record. Which creates a customer record related to the account.
When a customer record is created I use process builder to fire the second invocable process to create the invoice.
I am getting the error 'Future Method cannot be called from future or batch method.'
I can't understand why if I can call the first future method from process builder, and it has finished (as a customer record is created) then why can't I call the second future method from process builder also?
I then use another future method to create an invoice in the accounting software and pass it the customer ID returned from the first future method.
I have created 2 seperate apex classes. Both are invocable processes. When a status changes on the opportunity I use process builder to fire the first call to create the customer record. Which creates a customer record related to the account.
When a customer record is created I use process builder to fire the second invocable process to create the invoice.
I am getting the error 'Future Method cannot be called from future or batch method.'
I can't understand why if I can call the first future method from process builder, and it has finished (as a customer record is created) then why can't I call the second future method from process builder also?
Future methods are asynchronous. How will your logic know which method was called first?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm
It is the creation of the customer record which is the criteria for running the second call.
Thats Ok and why are you using the future annotation in the first place?
refer to this blog article by Bob on using Invokable Methods: http://bobbuzzard.blogspot.co.uk/2015/02/lightning-process-builder-and-invocable.html
Thankls :)
They are invoked by process builder which then does a callout to the webservice. The first one returns a customer number and stores it in a custom object related to the account.
When the custom object record is created that causes the second process builder to invoke the second call to the webservice to create the invoice.
It is when the second call is made that I get the error.
as you can see from the error report, the Account Id, Account Name and Xero Contact (Customer) Id are all set so the first call must have completed as the Xero_Contact__c custom object record has been created.
Thats what I am saying, you are trying to do a synchronous process there using future methods. If you read the problem stated in the idea here
https://success.salesforce.com/ideaView?id=08730000000BpR4AAK, that is what you are trying to do.
1. I know that you can invoke a future method with process builder as it is done in call 1.
2. I know the first process is completed because it has created the customer record.
Therefore I can't see what is stopping the second process builder from invoking a new future method.
I maybe wrong and there might be better ways to do it, however I will tell you how I did it in the past.
So let the first process flow remain as is. its working fine and inserting the required customer records.
Lightning - For creating invoices, why not create a lightning component and embed it in a quickAction (I assume you are using Lightning). Follow this post on how to build a webservice in a component (https://developer.salesforce.com/forums/?id=9060G000000XiheQAC). Now add this quickaction on the customer object record and click on it manually to generate an invoice for that customer with its relevant opp and account info.
Classic - Create a javascript button and call a webservice class. Again put this button on the customer object record and click on it to generate a invoice record.
Thanks
I am using Lightning but I have only ever created 1 lightning component and I'm not familiar with quick actions.
This whole process is an entirely automated one which takes the customer from filling in a sign up form on the website to having contracts electronically signed and payment authority set up without any human touchpoints other than the customer.
I need to find a way of getting the invoice created automatically.
Have you got the solution for this question?
Please help me if you got it.
Thanks!