I am calling php script which accesses my db from an android lass. The class is below;  public class pk_http {      // Progress Dialog     private ProgressDialog qDialog;      // JSON parser class     JSONParser jParser = new JSONParser();      class phpCall extends AsyncTask&lt;String, String, String&gt; {         @Override         protected String doInBackground(String... args) {             // Building Parameters             String url = args[0];             List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();             // getting JSON string from URL             JSONObject json = jParser.makeHttpRequest(url, "GET",params);                return null;         }    }   Now when i call that from my calling class (the calling class does not extend Activity btw) this way;  public static ArrayList&lt;String&gt; getLoginTileDataArray(Context c) {     //CODE STUB: HTTP GET RETURNS THE FOLLOWING STRING     String result = pk_http.phpCall.execute("http://myUrl/phpFile.php"); . . .   I have a error pre-compilation that says;     Non-static method 'execute(Params...) cannot be referenced from a   static context.   if i remove the 'sttic' no change. Am i calling the async method correctly?
1624
The very common beginner mistake is when you try to use a class property "statically" without making an instance of that class. It leaves you with the mentioned error message:     You can either make the non static method static or make an instance of that class to use its properties.   Why? I am not asking for solutions. I would be grateful to know what is the reason behind it. The very core reason!  private java.util.List&lt;String&gt; someMethod(){     /* Some Code */     return someList;             }  public static void main(String[] strArgs){                // The following statement causes the error. You know why..     java.util.List&lt;String&gt; someList = someMethod();          }
5085
I´m having problems with url parameters (req.requestURI) in my test class.  This is my code.  REST CLASS:  @RestResource(urlMapping='/Accounts/*') global class StoreController {       @HttpGet     global static String getAccounts() {           integer pageNumber=integer.valueof(RestContext.request.params.get('page'));         string  ptime=RestContext.request.params.get('time');         string  hash=RestContext.request.params.get('hash');      }   REST TEST CLASS:  @isTest private class StoreControllerTest {      static testMethod void testGet() {       //do request     RestRequest req = new RestRequest();      RestResponse res = new RestResponse();      req.requestURI = 'https://dev-my-my.cs14.force.com/mine/services/apexrest/Accounts?page=0&amp;time=1390296387&amp;hash=1wer2547';         req.httpMethod = 'GET';     RestContext.request = req;     RestContext.response = res;          String results = StoreController.getAccounts();      } }   When i run test class i get the error:  System.NullPointerException: Argument 1 cannot be null    for line :  integer pageNumber=integer.valueof(RestContext.request.params.get('page'));   Looks like parameters are not taken from url ''  when i run the test class.Please can you help me with this?
33754
Is something like the following possible in PHP?  $blah = 'foo1';  class foo2 extends $blah {     //... }  class foo1 {     //... }   This gives an error.  I want to dynamically set $blah so I can extend whatever class I want.  Edit: The reason for wanting to do this because I wanted to use a function out of another class in a related class. In the end it would have been something like:  Final extends foo1 extends foo2 extends foo3 extends foo4 extends parent { ... }   In the end I decided to instantiate the other class within the class and use it. Not the best options because they both you 2 of the same classes, but this won't be used that often, so it will work for now.
97172
Hi i am trying to write script for display list of records from wrapper class.   @remoteaction     public static wrappercls getaccounts(){         string account = 'select id,name,accountnumber from account';         listacc = database.query(account);         count = listacc.size();         system.debug('#####'+count);         wrappercls wra = new wrappercls(count,listacc);         return wra;     }      public class wrappercls{         public integer count11;         public list&lt;account&gt; account;          public wrappercls(integer count11,list&lt;account&gt; account){             this.count11 = count11;             this.account = account;         }     }    This class returns list of account records and record count parameter.Need to display these records in page.Is it possible if possible Please help me on this..  Script  &lt;script&gt;   function getallaccounts(){     exremote.getaccounts(         function(result,event){             if(event.status){              }             else {              }        },{escape:true}     ); } &lt;/script&gt;   Thanks in Advance...
107722
Is there some equivalent of "friend" or "internal" in php? If not, is there any pattern to follow to achieve this behavior?   Edit: Sorry, but standard Php isn't what I'm looking for. I'm looking for something along the lines of what ringmaster did.  I have classes which are doing C-style system calls on the back end and the juggling has started to become cumbersome. I have functions in object A which take in object B as a parameter and have to call a method in object B passing in itself as an argument. The end user could call the method in B and the system would fall apart.
54427
I have two classes: Action and MyAction. The latter is declared as:  class MyAction extends Action {/* some methods here */}   All I need is method in the Action class (only in it, because there will be a lot of inherited classes, and I don’t want to implement this method in all of them), which will return classname from a static call. Here is what I’m talking about:  Class Action {  function n(){/* something */} }   And when I call it:  MyAction::n(); // it should return "MyAction"   But each declaration in the parent class has access only to the parent class __CLASS__ variable, which has the value “Action”.  Is there any possible way to do this?
112290
This code throws a NullReferenceException when it calls ExecuteScalar:  selectedPassengerID = 0;  //SqlCommand command = GenericDataAccess.CreateCommand();   // 2nd test string connectionString = ""; SqlConnection conn;  connectionString = ConfigurationManager.     ConnectionStrings["ConnST-MHM"].ConnectionString; conn = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure ; command.Connection = conn; command.CommandText = "SearchForPassenger";  SqlParameter param;  param = command.CreateParameter(); param.ParameterName = "@name"; param.Value = pName; // Session[""]; param.DbType = DbType.String; command.Parameters.Add(param);  param = command.CreateParameter(); param.ParameterName = "@flightDate"; param.Value = date;  param.DbType = DbType.String; command.Parameters.Add(param);  param = command.CreateParameter(); param.ParameterName = "@ticketNo"; param.Value = ticketNumber;  param.DbType = DbType.Int32; command.Parameters.Add(param);  int item;  command.Connection.Open(); item = (int)command.ExecuteScalar();
16373
How do I pass have a Javascript script request a PHP page and pass data to it? How do I then have the PHP script pass data back to the Javascript script?  client.js:  data = {tohex: 4919, sum: [1, 3, 5]}; // how would this script pass data to server.php and access the response?   server.php:  $tohex = ... ; // How would this be set to data.tohex? $sum = ...; // How would this be set to data.sum? // How would this be sent to client.js? array(base_convert($tohex, 16), array_sum($sum))
55180
So I have a method that takes as a parameter an Id of a object and uses it to make an external callout.  Unfortunately I can't seem to figure out any way to test it.  @isTest static void sometimes_salesforces_sucks() {    My_Object__c foo = new My_Object__c(Name='test');    insert foo;    MyClient client = new MyClient();    MyMockResponseGenerator mockResponse = new MyMockResponseGenerator();    Test.setMock(HttpCalloutMock.class,mockResponse);     Test.startTest();    client.bar(foo.Id);    Test.stopTest(); }    says that using start/stop test should work, but it doesn't work for me
60323
My first post,pretty excited.I want to make a soap api call which insert multiple records. I am using 2 different salesforce instances. destination side  global with sharing class SoapDemo1 {    global class AccountWrapper    {       webservice string Name;       AccountWrapper(Account a)       {         this.Name=a.Name;       }    }     webservice static List&lt;Account&gt; CreateMultipleAccounts(List&lt;Account&gt; accs)    {        List&lt;Account&gt; FinalList=new List&lt;Account&gt;();         for(Account a:accs)        {           Account a1=new Account();           a1.Name=a.Name;            FinalList.add(a1);           }         if (FinalList.size() &gt; 0)        {           Database.Insert(FinalList);        }         return FinalList;     }     }   I generated the class wsdl file and also partner wsdl file  ****source side:**** I upload the class wsdl file generated from destination, when I parse no errors, but when I click Generated Apex code, it shows error as:     Unable to find complexType for   {}anyType    I changed anyType to string and again repeated the process but it shows error as:     Unable to find complexType for   {}JunctionIdListNames   Please help me out
77422
I have a call to a method in a class as follows:  String key1 = "test1"; String key2 = "test2";  long[] datalr = new long[] {}; datalr = TestClass.callerSub(key1,key2);   The test class is as follows:  public class TestClass {  Public TestClass { }  public long[] callerSub(string key1, String key2){  long[] datalr = new long[] {0,0};  datalr[0] = 2; datalr[1] = 3;  return datalr;  } }   I'm getting the following error in the first class:  Error: Compile Error: Method does not exist or incorrect signature: TestClass.callerSub(String, String) at line 54 column 12       which is the following line:  datalr = TestClass.callerSub(key1,key2);   The datalr data in the callerSub method is just an example above,  Any idea why?  Thanks
55087
i am building a app which takes input from user and then search to a remote database(MySql).And then display the retrieved data on VisualForce page.One important note that my app will be distributable.  here is my controller class  public with sharing class Search  {    public String strTag {get;set;}   public String strlocation {get;set;}    public PageReference find() {              return null;   } }   Thanks in advance.  Updated  public with sharing class Search  {   public String strTag {get;set;} public String strlocation {get;set;}   public PageReference find() {             HttpRequest req = new HttpRequest();   HttpResponse res = new HttpResponse();   Http http = new Http();    req.setEndpoint('https://localhost/salesforce/');   req.setMethod('POST');     req.setCompressed(false);   req.setBody('key1=value1&amp;key2=value2');   req.setHeader('Content-Type', 'application/x-www-form-urlencoded');      try {     res = http.send(req);   } catch(System.CalloutException e) {     system.debug('Callout error: '+ e);   }   system.debug(res.getBody());      return null;  } }   I am getting below error now      error message System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = localhost/salesforce
108487
I have the code below (I've included what I believe are all relevant sections):  private String readCommand = "SELECT LEVEL FROM USERS WHERE VAL_1 = ? AND VAL_@ = ?;"; public bool read(string id) {     level = -1;     MySqlCommand m = new MySqlCommand(readCommand);     m.Parameters.Add(new MySqlParameter("", val1));     m.Parameters.Add(new MySqlParameter("", val2));     MySqlDataReader r = m.ExecuteReader();     if (r.HasRows)         level = Convert.ToInt32(r.GetValue(0).ToString());     r.Close();     return true; }   When I run this, I get an IndexOutOfBoundsException on adding the first parameter. What have I done wrong?
77120
I am trying to implement  and below is my code and debug log - any help is appreciated.  Http httpProtocol = new Http();    HttpRequest request = new HttpRequest(); request.setHeader('Content-Type', 'application/json;'); request.setEndPoint('https://test.salesforce.com/services/oauth2/token'); request.setMethod('POST'); String strbody = '{"grant_type":"Password", "password":"MY PASSWORD + TOKEN", "username":"SANDBOX USER NAME",  "client_secret":"secret",   "client_id":"Client id from remote setttings"}'; request.setBody(strbody); HttpResponse response = httpProtocol.send(request); String jsonInput = response.getBody(); system.debug('jsonInput===&gt;'+jsonInput);   Debug log -   15:55:38.068 (68324000)|SYSTEM_METHOD_ENTRY|[5]|System.HttpRequest.setMethod(String) 15:55:38.068 (68346000)|SYSTEM_METHOD_EXIT|[5]|System.HttpRequest.setMethod(String) 15:55:38.068 (68350000)|STATEMENT_EXECUTE|[6] 15:55:38.068 (68356000)|HEAP_ALLOCATE|[6]|Bytes:357 15:55:38.068 (68381000)|VARIABLE_ASSIGNMENT|[6]|strbody|"{\"grant_type\":\"Passw (337 more) ..." 15:55:38.068 (68387000)|STATEMENT_EXECUTE|[7] 15:55:38.068 (68407000)|SYSTEM_METHOD_ENTRY|[7]|System.HttpRequest.setBody(String) 15:55:38.068 (68440000)|SYSTEM_METHOD_EXIT|[7]|System.HttpRequest.setBody(String) 15:55:38.068 (68445000)|STATEMENT_EXECUTE|[8] 15:55:38.068 (68478000)|SYSTEM_METHOD_ENTRY|[8]|System.Http.send(APEX_OBJECT) 15:55:38.068 (68568000)|CALLOUT_REQUEST|[8]|System.HttpRequest[Endpoint=https://test.salesforce.com/services/oauth2/token, Method=POST] 15:55:38.483 (483258000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:219 15:55:38.483 (483399000)|CALLOUT_RESPONSE|[8]|System.HttpResponse[Status=Bad Request, StatusCode=400] 15:55:38.483 (483424000)|HEAP_ALLOCATE|[8]|Bytes:96 15:55:38.483 (483444000)|SYSTEM_METHOD_EXIT|[8]|System.Http.send(APEX_OBJECT) 15:55:38.483 (483615000)|VARIABLE_ASSIGNMENT|[8]|response|"System.HttpResponse[Status=Bad Request, StatusCode=400]"|0x1b22c3f1 15:55:38.483 (483627000)|STATEMENT_EXECUTE|[9] 15:55:38.483 (483666000)|SYSTEM_METHOD_ENTRY|[9]|System.HttpResponse.getBody() 15:55:38.483 (483742000)|HEAP_ALLOCATE|[9]|Bytes:81 15:55:38.483 (483751000)|SYSTEM_METHOD_EXIT|[9]|System.HttpResponse.getBody() 15:55:38.483 (483780000)|VARIABLE_ASSIGNMENT|[9]|jsonInput|"{\"error\":\"unsupporte (61 more) ..." 15:55:38.483 (483786000)|STATEMENT_EXECUTE|[10] 15:55:38.483 (483794000)|HEAP_ALLOCATE|[10]|Bytes:13 15:55:38.483 (483980000)|HEAP_ALLOCATE|[10]|Bytes:94 15:55:38.483 (483999000)|SYSTEM_METHOD_ENTRY|[10]|System.debug(ANY) 15:55:38.484 (484025000)|USER_DEBUG|[10]|DEBUG|jsonInput===&gt;{"error":"unsupported_grant_type","error_description":"grant type not supported"}
72839
I've been trying to read through the SalesForce documentation on how to call a custom Method like this via cURL:  @RestResource(urlMapping='/Test/*') global with sharing class RestTest  {     @HttpGet     global static Account getAccount()     {         Account a = [select Id, Name from Account WHERE Name = 'wizzbang' limit 1];         return a;     } }   My gut tells me this should be something as simple as:  $ curl -i -H "Accept: application/json" -H "Content-Type: application/json"  -X GET https://mydomain.salesforce.com/services/apexrest/test/   But I get back that this is unauthenticated. I've gone through the guide and it says I have to setup a "connected app." I've done this...I think. But I'm not sure what my CallbackURL should be? Further, I don't get what I need to make my curl statement look like in order to call the service? Can someone explain what I need to do? This seems horribly overengineered.
18923
I am trying to write a test for a trigger that is firing a future apex callout :  The trigger calls the callBillingService method from this class:  public class BillingCalloutService {     //Implement business and callout logic methods here     @Future(callout=true)     public static void callBillingService(List&lt;Id&gt; recordIds) {         List&lt;Project__c&gt; projects = [Select Id, ProjectRef__c,Billable_Amount__c from Project__c Where Id = :recordIds];          List&lt;Project__c&gt; projectsToUpdate = new List&lt;Project__c&gt;();          String username = ServiceCredentials__c.getValues('BillingServiceCredential').Username__c;         String password = ServiceCredentials__c.getValues('BillingServiceCredential').Password__c;          String auth = username + ':' + password;         String encodedAuth = EncodingUtil.base64Encode(Blob.valueOf(auth));          for(Project__c p : projects) {              BillingServiceProxy.InvoicesPortSoap11 service = new BillingServiceProxy.InvoicesPortSoap11();             service.inputHttpHeaders_x = new Map&lt;String, String&gt;();             service.inputHttpHeaders_x.put('Authorization', 'Basic ' + encodedAuth);              BillingServiceProxy.project project = new BillingServiceProxy.project();             project.username = username;             project.password = password;             project.projectRef = p.ProjectRef__c;             project.billAmount = p.Billable_Amount__c;              if(service.billProject(project).equals('ok')){                 projectsToUpdate.add(new Project__c(ProjectRef__c = p.ProjectRef__c, Status__c = 'Billed'));             }         }         shouldIRun.stopTrigger();         upsert projectsToUpdate ProjectRef__c;     } }   Error     Methods defined as TestMethod do not support Web service callouts   Test Class  @IsTest private class BillingCalloutServiceTest {      @IsTest     private static void testBillingCalloutService() {     Account a = new Account(Name = 'Acme');     insert a;     Opportunity o = new Opportunity(Name='Test', StageName='Submitted Project', AccountId=a.Id, Amount=1000, CloseDate=Date.Today());     insert o;     Project__c p = new Project__c(Status__c='Running',Start_Date__c=Date.Today(),End_Date__c=Date.Today(),Billable_Amount__c=10000,ProjectRef__c='projectX',Opportunity__c=o.Id);     insert p;      insert new ServiceCredentials__c(Name='BillingServiceCredential',Username__c='toto', Password__c='azerty');      Test.startTest();     Test.setMock(HttpCalloutMock.class, new BillingCalloutServiceMock());       p.Status__c = 'Billable';       update p;     Test.stopTest();     // runs callout and check results     p = [select Status__c from Project__c where id =: p.id];     System.assertEquals('Billed', p.Status__c);     }  }
24549
So I'm refactoring my code to implement more OOP.  I set up a class to hold page attributes.  class PageAtrributes  {   private $db_connection;   private $page_title;      public function __construct($db_connection)      {         $this-&gt;db_connection = $db_connection;         $this-&gt;page_title = '';     }      public function get_page_title()     {         return $this-&gt;page_title;     }      public function set_page_title($page_title)     {         $this-&gt;page_title = $page_title;     } }   Later on I call the set_page_title() function like so  function page_properties($objPortal) {         $objPage-&gt;set_page_title($myrow['title']); }   When I do I receive the error message:     Call to a member function set_page_title() on a non-object   So what am I missing?