+ Start a Discussion

apex ConvertLead - occasionally slow?

Hello - i have an apex webservice which creates a new Lead based on incoming information and, conditionally, Converts the Lead to an Account/Contact/Opportunity using Database.convertLead.  occasionally - maybe 10% of the time (no pattern i can find) - it takes a very long time to run this method.  i added some logging so that i could see the timestamp at various spots in the code, and the convertLead method takes 2-3 minutes to complete.  (this causes some problems because the code is part of an apex web service - so the system calling the web service gets a timeout.

has anyone had a similar issue?  any thoughts?  i've considered doing the conversion asynchronously, but i need to return the newly created Ids to the calling system.

PrasanntaPrasannta (Salesforce Developers) 

Timeout error occurs because webservice takes a while to get a response because it loads lots of data.

Here's an example of setting a custom timeout for Web services callouts:

Try setting the custom timeout for web service in apex class as-
stub.timeout_x = 2000; // timeout in milliseconds

Hope this helps.