You need to sign in to do that
Don't have an account?
Venkateswarlu Ch
How to use /services/data/v33.0/queryAll/?q=SELECT+Name+from+Account
I have two salesforce orgs A and B. I am want to get all Account records there in B org in Org A. I written code REST API. Eevrything workig fine. But how to user pass: /services/data/v29.0/queryAll/?q=SELECT+Name+from+Account. this use this funciton in REST API.
Below is my Code:
public class W_RestInvoke_Account2c{
public String result{set;get;}
fromJSON d1 {set;get;}
// JSON2Apex d2 {set;get;}
public String d3 {set;get;}
public String accesstkn {set;get;}
Account accrec {set;get;}
public String clientid ;
public void show(){
Http p =new Http();
HttpRequest request=new HttpRequest();
request.setEndpoint('https://login.salesforce.com/services/oauth2/token');
request.setMethod('POST');
request.setBody('grant_type=password&client_id=tw&client_secret=7925616023235447130&username=cxxxm&password=xxx' );
HttpResponse res=p.send(request);
result=res.getBody();
//string tknAccesstoken = (String) res.getAttribute(ACCESS_TOKEN);
d1 = (fromJSON)JSON.deserialize(result, fromJSON.class);
accesstkn = d1.access_token;
system.debug('VENKATESH______-->fromJSONvalues:Y'+ accesstkn );
HttpRequest request1= new HttpRequest();
request1.setEndpoint('https://ap1.salesforce.com/services/apexrest/RestAccount2');
request1.setMethod('GET');
request1.setHeader('Authorization','OAuth '+accesstkn);
request1.setHeader('q','/services/data/v29.0/queryAll/?q=SELECT+Name+from+Account');
HttpResponse response=p.send(request1);
result= ''+response.getBody();
public class fromJSON{
public String id;
public String issued_at;
public String token_type;
public String instance_url;
public String signature;
public String access_token;
}
}
Pls help me where can use this /services/data/v29.0/queryAll/?q=SELECT+Name+from+Account function?
Below is my Code:
public class W_RestInvoke_Account2c{
public String result{set;get;}
fromJSON d1 {set;get;}
// JSON2Apex d2 {set;get;}
public String d3 {set;get;}
public String accesstkn {set;get;}
Account accrec {set;get;}
public String clientid ;
public void show(){
Http p =new Http();
HttpRequest request=new HttpRequest();
request.setEndpoint('https://login.salesforce.com/services/oauth2/token');
request.setMethod('POST');
request.setBody('grant_type=password&client_id=tw&client_secret=7925616023235447130&username=cxxxm&password=xxx' );
HttpResponse res=p.send(request);
result=res.getBody();
//string tknAccesstoken = (String) res.getAttribute(ACCESS_TOKEN);
d1 = (fromJSON)JSON.deserialize(result, fromJSON.class);
accesstkn = d1.access_token;
system.debug('VENKATESH______-->fromJSONvalues:Y'+ accesstkn );
HttpRequest request1= new HttpRequest();
request1.setEndpoint('https://ap1.salesforce.com/services/apexrest/RestAccount2');
request1.setMethod('GET');
request1.setHeader('Authorization','OAuth '+accesstkn);
request1.setHeader('q','/services/data/v29.0/queryAll/?q=SELECT+Name+from+Account');
HttpResponse response=p.send(request1);
result= ''+response.getBody();
public class fromJSON{
public String id;
public String issued_at;
public String token_type;
public String instance_url;
public String signature;
public String access_token;
}
}
Pls help me where can use this /services/data/v29.0/queryAll/?q=SELECT+Name+from+Account function?
request1.setEndpoint('https://ap1.salesforce.com//services/data/v29.0/queryAll/?q=SELECT+Name+from+Account');
Are you going to do this one time or going to schedule it?
if it is one time, you could just export from org 1 and import in org2 using data loader.
if you want to share the data, then you can look into salesforce to salesforce.
if you want to scehdule your code above, you should not be selecting all the account each time it runs, you can get only new record and modified records and the upsert it to another org.
https://www.salesforce.com/us/developer/docs/api_rest/Content/dome_get_updated.htm