• Mouse.liu
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies

Hello,

 

I am new to all the force.com stuff, so please forgive me if I am using the wrong terminology or am unclear. I will try to be as clear as I can. 

 

My goal is to build a java application that periodically monitors a user chatter stream. I am not running this code via a web browser or application server - this is pure java on the command line. I have setup a test remote application and have a valid client key and client secret key.

 

My goal is to have the user enter a username/password for the initial authentication and then to use the access_token / refresh_token flow for subsequent runs. Thus, in the User-Agent flow code below, my callback URI doesn't really point to anything legitimate - I want to do this all in code if possible.

 

Trying to implement the User-Agent flow as described here (http://www.salesforce.com/us/developer/docs/chatterapi/index.htm , "Understanding the User-Agent OAuth Flow" article), my code looks like this:

 

----

// chatter.auth.url == https://login.salesforce.com/services/oauth2/authorize

String hostUrl = System.getProperty("chatter.auth.url"); 


String clientId = System.getProperty("chatter.oauth.consumerKey");
String clientSecret = System.getProperty("chatter.oauth.consumerSecret");


HttpPost post = new HttpPost(hostUrl);

HttpParams params = new BasicHttpParams();
params.setParameter("client_id", clientId);

params.setParameter("redirect_uri", "https%3A%2F%2Flocalhost%3A8080%2FConnectTest%2Foauth%2F_callback");
params.setParameter("response_type", "token");
post.setParams(params);

 

response = clientService.execute(post);

 

----

 

When I run the above code, I receive a response that says "error=unsupported_response_type&error_description=response%20type%20not%20supported"

 

I have tried another API reference which uses the password method of OAuth authentication (http://www.salesforce.com/us/developer/docs/chatterapi/index.htm , "Step Two: Connect to Chatter API Using OAuth"). Based on that article, my code looks like this:

 

----

// chatter.token.url == https://na14.salesforce.com/services/oauth2/token

String hostUrl = System.getProperty("chatter.token.url");  
String clientId = System.getProperty("chatter.oauth.consumerKey");
String clientSecret = System.getProperty("chatter.oauth.consumerSecret");


HttpPost post = new HttpPost(hostUrl);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");

HttpParams params = new BasicHttpParams();
params.setParameter("grant_type", "password");
params.setParameter("client_id", clientId);
params.setParameter("client_secret", clientSecret);
params.setParameter("username", username);
params.setParameter("password", password);
post.setParams(params);

 

response = clientService.execute(post);

 

----

 

When I execute the above code, I get a JSON response that says "error:  grant_type_unsupported". The short of it is that I cannot get an authorization token or a session token or anything else returned from my attempts to connect via OAuth. 

 

What am I doing wrong here or missing?  I am very confused and can't get any code that I have found in the API documentation to work and provide the documented response. 

 

Any help at all would be greatly appreciated!

Hi

 

I am calling a VF page from a Custom Button. I have successfully managed to display an alert to the user if certain conditions are met. How can I redirect the user to the original page that had the custom button after this message is displayed? I am displaying the message using the following:-

 

 <script language = "JavaScript">
   var msg = 'There is no valid Contact Record or Contact Role - You may not send an Email until this is done.'
   if ('{!validtoflag}' == 0) {
   	alert (msg);
   }
 </script>

 

 Many thanks

Ross

 

  • April 12, 2012
  • Like
  • 0

Hi I Need help for convering Amount to Words in INR Format.

 

For Instance:

1987765:

Nineteen Lakh Eighty Seven Thousand Seven Hundred and Sixty Five.

Can any one help me !!!!!

Urgent Requirement.

 

Thanks in Advance.

Hi sir,

I am working on salesforce development from last 2 months,but i am not able to become expert  in apex programming..what is the basic program we should know to become a successfull programmer in Apex..Any books ,or any guidance please?

Hello,

 

 

var query = "Select LastName,FirstName,MobilePhone,Id from Contact where " + idCondition;

var result = sforce.connection.query(query);

var contacts = result.getArray("records");

 

The above piece of code shows the following error, {faultcode:'soapenv:Client', faultstring:'Attribute "xmlns" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "query".', }

 

Please help me to figure it it out.

 

Thanks in advance

Hi Folks,
 
we created public site on a customer portal and while  inserting few opportunitylineitems for a newly created opportunity we are getting this error..

"Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []"


The steps are..

#1 Insert a opportunity..

#2 Insert Few opportunitylineitems on the basis of some buiseness logic for the opportunity created in step1


Sample code is something like this.
 
ContactId= CurrentLoggedUsersContactId ;
Opportunity Opp = new Opportunity(with all required details filled......);
insert  Opp;
 
OpportunityLineItem Oli = new  OpportunityLineItem (Contact__c = ContactId,UnitPrice=40.0,PricebookEntryId=01uT0000000pbcuIAA,OpportunityId= Opp.Id);

Insert Oli;//Error comes right at this line of code 
 
I check all the 3 Ids provided in insert call are valid.
 
 
 
This thing was working fine before the spring 10 release.

IS this because of the new release??

Please guide if any one knows or faced a similar problem.


Thanks
Nikhil Jain
  • February 01, 2010
  • Like
  • 0

Can someone tell me what I'm missing here.  In the debug log it says no records found after I update an OpportunityLineItem record:

 

Trigger.oppLineItem_prod_data_trigger2: line 20, column 33: SOQL query with 0 rows finished in 3 ms

 

trigger oppLineItem_prod_data_trigger2 on OpportunityLineItem (after insert, after update) { Set<String> opportunityLineItemIDs = new Set<String>(); List<OpportunityLineItem> updtOpportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] opportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] oliList = [select pricebookentry.product2.bu_code__c FROM OpportunityLineItem where id in :opportunityLineItemIDs]; for(OpportunityLineItem oli : oliList) { oli.bu_code__c = oli.pricebookentry.product2.bu_name__c; } update oliList; }

 

Hi,
 
Im using ANT Tool to deploy triggers.When i ran the ant deploy command in cmd prompt im getting the following error
 
 
E:\sample>ant deploy -verbose
Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: build.xml
Detected Java version: 1.6 in: C:\Program Files\Java\jdk1.6.0\jre
Detected OS: Windows XP
parsing buildfile E:\sample\build.xml with URI = file:/E:/sample/build.xml
Project base dir set to: E:\sample
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apach
e/tools/ant/antlib.xml. It could not be found.

 [property] Loading E:\sample\build.properties
 [property] Loading Environment env.
Build sequence for target(s) `deploy' is [deploy]
Complete build sequence is [deploy, delete, ]
deploy:
 [setproxy] Setting proxy to <proxy host>:80
parsing buildfile jar:file:/E:/apache-ant-1.7.0/lib/ant-salesforce.jar!/com/sale
sforce/antlib.xml with URI = jar:file:/E:/apache-ant-1.7.0/lib/ant-salesforce.ja
r!/com/salesforce/antlib.xml
[sf:compileAndTest] Using proxy: <proxy host>:80 user <username> [sf:compileAndTest] compileAndTest on https://www.salesforce.com/services/Soap/u
/12.0, compiling 0 classes and 0 triggers, deleting 0 classes and 0 triggers
[sf:compileAndTest] note: use ant -verbose to get more information on the failur
e
BUILD FAILED
E:\sample\build.xml:14: Failed to login:Unexpected element. Parser was expecting
 element 'urn:partner.soap.sforce.com:organizationId' but found 'urn:partner.soa
p.sforce.com:orgDefaultCurrencyIsoCode'

        at com.salesforce.ant.CompileAndTest.execute(CompileAndTest.java:190)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: com.sforce.ws.ConnectionException: Unexpected element. Parser was exp
ecting element 'urn:partner.soap.sforce.com:organizationId' but found 'urn:partn
er.soap.sforce.com:orgDefaultCurrencyIsoCode'
        at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:363)
        at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:392)
        at com.sforce.soap.partner.GetUserInfoResult.loadFields(GetUserInfoResul
t.java:455)
        at com.sforce.soap.partner.GetUserInfoResult.load(GetUserInfoResult.java
:439)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.soap.partner.LoginResult.loadFields(LoginResult.java:263)
        at com.sforce.soap.partner.LoginResult.load(LoginResult.java:226)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.soap.partner.LoginResponse_element.loadFields(LoginRespons
e_element.java:68)
        at com.sforce.soap.partner.LoginResponse_element.load(LoginResponse_elem
ent.java:59)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:136)
        at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:11
0)
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:92)
        at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.jav
a:1193)
        at com.sforce.soap.partner.PartnerConnection.<init>(PartnerConnection.ja
va:301)
        at com.sforce.soap.partner.Connector.newConnection(Connector.java:27)
        at com.salesforce.ant.CompileAndTest.execute(CompileAndTest.java:120)
        ... 17 more
--- Nested Exception ---
com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting elem
ent 'urn:partner.soap.sforce.com:organizationId' but found 'urn:partner.soap.sfo
rce.com:orgDefaultCurrencyIsoCode'
        at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:363)
        at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:392)
        at com.sforce.soap.partner.GetUserInfoResult.loadFields(GetUserInfoResul
t.java:455)
        at com.sforce.soap.partner.GetUserInfoResult.load(GetUserInfoResult.java
:439)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.soap.partner.LoginResult.loadFields(LoginResult.java:263)
        at com.sforce.soap.partner.LoginResult.load(LoginResult.java:226)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.soap.partner.LoginResponse_element.loadFields(LoginRespons
e_element.java:68)
        at com.sforce.soap.partner.LoginResponse_element.load(LoginResponse_elem
ent.java:59)
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:564)
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)
        at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:136)
        at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:11
0)
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:92)
        at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.jav
a:1193)
        at com.sforce.soap.partner.PartnerConnection.<init>(PartnerConnection.ja
va:301)
        at com.sforce.soap.partner.Connector.newConnection(Connector.java:27)
        at com.salesforce.ant.CompileAndTest.execute(CompileAndTest.java:120)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 4 seconds
 
This is the first time i'm trying to deploy,so not sure why im getting this error. Is there any thing to do with mutiple currency since multi currencies are enabled in my org.Is it the problem with some classpath.
Any pointers will be of great help.
Thnaks in advance.
  • March 12, 2008
  • Like
  • 0
While creating AJAX Toolkit apps I encountered an unexpected error, saying
uncaught exception: {faultcode:'soapenv:Client', faultstring:'Attribute "xmlns" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "query".', }
After long time debugging I finally found out following two libraries are conflicting, prototype.js and AJAX Toolkit. This simple S-Control would raise same error message.

Code:
<html>
  <head>
    <script type="text/javascript" src="/soap/ajax/8.0/connection.js"></script>
    <script type="text/javascript" src="http://prototypejs.org/assets/2007/1/18/prototype.js"></script>
    <script type="text/javascript">    
window.onload = function() {
  var res = sforce.connection.query('SELECT count() FROM Account', function(res) { alert(res.size) })
}
    </script>
  </head>
  <body>
  </body>
</html>
It appears that some array prototype overiding in prototype.js causes this problem. Now prototype.js is one of the most major JavaScript library, do you have any workaround from AJAX Toolkit side?
  • January 30, 2007
  • Like
  • 0