function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel ThomsonDaniel Thomson 

getting a problem during creating an account through my java code with SOAP Api

Account ac = new Account();
      //SObject rec = new Account();

      System.out.println("Enter your name \n");
      ac.setName(br.readLine());
      System.out.println("Enter your Mobile No. \n");
      ac.setPhone(br.readLine());
      //rec = ac;
      SaveResult save = connection.create(ac);


      System.out.println(ac.getParentId());

 

 

I am getting an error at the bolded line. actually I want to create the accoutn  my user but that create statement  needs the array of  SObject[].......................

 

 

so waht shold i do..................

 

can anyone help me................

 

thanks................

Best Answer chosen by Admin (Salesforce Developers) 
VirendraVirendra

Try as  Following 

Account createAccounts []= new Account[1];
Account ac = new Account(); 

      System.out.println("Enter your name \n");

      ac.setName(br.readLine());

      System.out.println("Enter your Mobile No. \n");

      ac.setPhone(br.readLine());

      createAccounts[0]= ac;  

      SaveResult[] saveR = connection.create(createAccounts);
      if(saveR[0].isSuccess())  

          Id = saveR[0].getId();

All Answers

VirendraVirendra

Try as  Following 

Account createAccounts []= new Account[1];
Account ac = new Account(); 

      System.out.println("Enter your name \n");

      ac.setName(br.readLine());

      System.out.println("Enter your Mobile No. \n");

      ac.setPhone(br.readLine());

      createAccounts[0]= ac;  

      SaveResult[] saveR = connection.create(createAccounts);
      if(saveR[0].isSuccess())  

          Id = saveR[0].getId();

This was selected as the best answer
Daniel ThomsonDaniel Thomson

Thanks.......................

 

I have done that and its usefull and got my result......................