Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Perl, PHP, Python & Ruby Development
- :
- Re: Create trigger code using php/java dynamically
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 04:04 PM
BTW - I would create the zip manually to begin with, get the deploy() working, then look at how to create a zip in Java - there seems to be plenty of sample code for that out there.
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 04:15 PM
Awesome, I ll try it out and let you know what happens :) . So there is no way to create the trigger more gracefully like by using the ApexTrigger object and then setting its content , name, version etc and then covert that to a file , something on those lines as oppose to manually writing my Trigger text to a file, just a thought.
So something like this
ApexTrigger trig = new ApexTrigger();
trig.setApiVersion(API_VERSION);
trig.setContent("some trigger code".getBytes());
ds.setFullName("TestTrigger.trigger");
and then make a trigger and its metadata xml out of this object ?
I am going try out the approach you suggested now, thanks a lot Pat.
- Hitesh
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 04:43 PM
No - unfortunately the only supported calls for ApexTrigger are deploy(), retrieve(), describeMetadata() and listMetadata() - see http://www.salesforce.com/us/developer/docs/api_me
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 05:46 PM
Yes I went through the docs. The good news is everything worked retrieved , created my new trigger, zipped it up and then deployed and it all works like a charm!
Thanks Pat!
So this was the ground work for the real thing we were trying to achieve. What we want to do is, once our application goes in the market, we want like a webpage within the application where a user can select object they want a trigger on, select the on update / up create / on delete and select a couple of internal parameters and once he hits save button I'll run this code which I just wrote to create the new trigger and then I will deploy it in the customers org.
Now to do that the user of the application needs to give me an adminitrator username, password_securityToken of their org for me to be able to create a connection with them and deploy to it. But the road block is that why would the user give us their adminitrator account, so the question is, is there a way to leverage the session credentials the user is already logged in with, or do this with apex or some way in which I will not require the users username and password+securitytoken?
Does the question make sense? Let me know if I need to be more clear. Looking forward to your reply!
Thanks Pat !!
- Hitesh
Re: Create trigger code using php/java dynamicall y
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 07:42 PM - edited 11-10-2011 07:42 PM
Hi Hitesh,
OAuth 2.0 will redirect the user to authenticate at salesforce.com and provide your app with a token that it can use to access APIs in the context of that user, so your app never needs to see the user's password - see this article for a detailed explanation of OAuth 2.0 on Force.com.
There are Java OAuth 2.0 libraries out there, or you can see sample Java code to do OAuth in this article. After the user has logged in and authorized your app to access their data, your app will receive a JSON (or XML) formatted structure containing an access token, instance URL etc:
{
"id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW /00550000001fg5OAAQ",
"issued_at":"1296458209517",
"refresh_token":"5Aep862eWO5D.7wJB...",
"instance_url":"https://na1.salesforce.com",
"signature":"0/1Ldval/TIP...",
"access_token":"00D50000000IZ3Z!AQ0AQ..."
}
OAuth integrates well with the Force.com REST API, but, with a little work, you can also use it with the SOAP or Metadata API. The access token above is equivalent to the session ID in the SOAP and Metadata APIs, while the id property points to a service that will return information on the user and their environment, including the Metadata API. You can GET the id URL, passing the access token as an HTTP header:
Authorization: OAuth 00D50000000IZ3Z!AQ0AQDpEDKYsn7ioKug2aSmgCjgrPjG...
You will receive another JSON structure with the Metadata endpoint formatted thus:
https://na1.salesforce.com/services/Soap/m/{version}/00D50000000IZ3Z
You will need to substitute the actual API version you want to use in that string to make a real endpoint:
https://na1.salesforce.com/services/Soap/m/23.0/00D50000000IZ3Z
Now you can push that into the Metadata connection, like this:
ConnectorConfig metadataConfig = new ConnectorConfig();
metadataConfig.setSessionId(accessTokenFromOAuth);
metadataConfig.setServiceEndpoint(metadataEndpointFromIdentityService);
MetadataConnection metadataConnection = com.sforce.soap.metadata.Connector.newConnection(m etadataConfig);
Now you can call the Metadata API as before.
Cheers,
Pat
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-10-2011 09:56 PM
Interesting! I'll try it out and let you know how it goes :).
Once again thanks a lot Pat !!
- Hitesh
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2011 06:25 PM
It all worked!!
Thanks a lot.
- Hitesh
Re: Create trigger code using php/java dynamicall y
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2011 09:18 PM
Awesome! Glad to hear it - thanks for reporting back :)
Cheers,
Pat

