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
Stanley He (skype: konafornia)Stanley He (skype: konafornia) 

Looking for Java sample to upadate ApexTrigger

1. In this reference, ApexTriggerMember is mentioned, but I cannot turn it into a working sample. http://redcurrantscloud.blogspot.in/2013/09/forcecom-tooling-api-create-apex-class.html

2. Forllowing this http://www.javacodegeeks.com/2014/06/how-to-use-salesforce-rest-api-with-your-javaserver-pages.html ,
 Works fine to update Account, if I tried it against ApexTrigger, still not working. Following is my code, and the error I got is "Response Status line :HTTP/1.1 400 Bad Request".

Please tell me what I missed. Thank you very much!
~Stanley

______________________________________________________________
CloseableHttpClient httpclient = HttpClientBuilder.create().build(); //HttpClients.createDefault();
            
            // http://mvnrepository.com/artifact/org.json/json/20140107
            JSONObject update = new JSONObject();

            update.put("Name", "TestTrigger");
            update.put("Body", "trigger TestTrigger on Opportunity (before insert){}");
            update.put("TableEnumOrId","Opportunity");

            HttpPost httpost = new HttpPost(instance_URL
                    + "/services/data/v32.0/tooling/sobjects/ApexTrigger/"  
                    + "01qi0000000GJn7" + "?_HttpMethod=PATCH");

            
            httpost.addHeader("Authorization", "OAuth " + access_token);
            httpost.addHeader("Accept", "application/json");
            httpost.addHeader("Content-Type", "application/json");
            
            System.out.println("---update.toString():" + update.toString());
            
            StringEntity messageEntity = new StringEntity(update.toString(),
                    ContentType.create("application/json"));

            httpost.setEntity(messageEntity);

            // Execute the request.
            CloseableHttpResponse closeableresponse = httpclient
                    .execute(httpost);
            System.out.println("Response Status line :"
                    + closeableresponse.getStatusLine());

            try {
                System.out.println("HTTP status "
                        + closeableresponse.getStatusLine().getStatusCode());
            } finally {
                httpclient.close();
            }
        }