How to test controller method with parameters which is called from Javascript.

public void insertProcess(String id,String str) {         

        if its last record i am calling the below method
      List<obj1__c> dd1inst = [select Id,field__c from obj1__c where Id in :mp.keyset()];
         obj2__c[] insrtdoc2 = new List<obj2__c>();
         for(obj1__c d1:dd1inst) {
              obj2__c dd2inst = new obj2__c();
              dd2inst.field1__c = d1.field__c;
              dd2inst.field2__c = mp.get(Id);  --> i want to test whether proper String(associated to Id from above method) is written to obj2

       insert insrtdoc2;
  • I've formatted your post so the parts of your code you've included displays properly. Please tell us what you've tried and what's preventing you from being able to test your code. I don't see an attempt at a test class included in the code you've posted. You can add it by clicking on the edit link at the bottom left of your question. After pasting code, select it and click on the {} icon to format it for display.
    – crmprogdev
    Jun 7, 2015 at 3:14
  • Are you asking how to call this method from javascript? Please elaborate your question. Jun 7, 2015 at 3:32

1 Answer 1


The fact that your code is called from Javascript is irrelevant. You need to look at it like you are simply testing the method and ensuring the business logic is met. With that in mind this would be your starting point

private static testmethod void basicTest(){
   insertProcess(YOURID, YOURSTRING);


 //Assert that the appropriate records were created / updated

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .