+ Start a Discussion

How to execute batch future callouts to download PDFs

I have a challenge in a current design that the client requires datasheets for each product that is added to the quote to be saved as a pdf on that quote in the notes and attachments. I use a future callout when the item is saved that downloads the datasheet from a URL and this works fine under normal quote creation.
The issue I have is when a quote is cloned, the future callout is called in a batch method which is not allowed by salesforce. I receive this error when I copy:
10:26:54:808 FATAL_ERROR System.AsyncException: Future method cannot be called from a future or batch method: class.savePdfFromBlob(String, Id, String)
I know there is queueable methods but I am not sure how to call upon this with the data i need to download the appropriate datasheets. In the example salesforce gives:
public class AsyncExecutionExample implements Queueable { public void execute(QueueableContext context) { Account a = new Account(Name='Acme',Phone='(415) 555-1212'); insert a;
} }
Is there a way to pass information to this queueable context call? I would need to pass the list of datasheets that need to be downloaded.
Or is there another way around this to download all of the datasheets on the quote copy?
NagendraNagendra (Salesforce Developers) 
Hi James,

You can define a constructor separate from the execute method which takes in and sets parameters top to be used in execute. Is this what you're missing?
System.enqueueJob(new QueueableClass(listOfDatasheets));
Hope this helps.

Kindly mark this as solved if the information was helpful.