You need to sign in to do that
Don't have an account?

Submitting multiple records using custom button
Hi, I need to create a custom buton (Detail Page Button/OnClick Java script) on opportunity page. When user clicks on custom button, all the opportunity records which have parent has current opportunity has to be submitted for approval. (I have cretaed a custom opportunity lookup field parent_opportunity__c on opportunity object). I have developed below java script to submit multiple child records to approval process. I see that only last record in the loop is getting submitted and the rest of the records are not submitted for approval process. what is missing here? What fix is required in below code.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} var result3 = sforce.connection.query("Select id,name From Opportunity o WHERE o.Parent_Opportunity__c = '{!Opportunity.Id}'"); var newOpp3 = result3.getArray("records"); for (var i=0; i<newOpp3.length; i++) { var temp = newOpp3[i]; var opptyId = temp.Id; window.location.href = "/p/process/Submit?retURL=/" + opptyId + "&id=" + opptyId; alert(temp.Name + " -- " + temp.Id + opptyId ); }
You can call it form the java script like
All Answers
You can call it form the java script like
Couple of things
1. You are using wrong javascript code. Just use the javascript code that I mentioned in my first answer.
2. Check the security for your class (Open class from Apex classes and click on security and add all profiles that need access to the class)
3. I hope you modified your processAutoSubmission method to include query, return message, error handling etc.
I couldnt figure out the exact problem in my original script. But your suggested code works.