Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String content = '{"Name": "Some acoount", "Phone":"9742882954"}';
- HttpRequest req = new HttpRequest();
- req.setEndpoint('https://ap1.salesforce.com/services/apexrest/Accountacc');
- req.setMethod('POST');
- String username = 'sarvesh01@gmail.com';
- String password = 'parvati@3';
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'BASIC ' +
- EncodingUtil.base64Encode(headerValue);
- req.SetBody(content);
- req.setHeader('Content-Type', 'application/json; charset=utf-8');
- req.setHeader('Authorization', authorizationHeader);
- req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
- Http http = new Http();
- HTTPResponse res = http.send(req);
- System.debug(res.getBody());
- @RestResource(urlMapping='/Accountacc/*')
- global with sharing class callAccount {
- @HttpPost
- global static String doPost() {
- RestRequest request = RestContext.request;
- RestResponse response = RestContext.response;
- String jSONRequestBody=request.requestBody.toString().trim();
- Account accObj = (Account)JSON.deserializeStrict(jSONRequestBody,Account.class);
- insert accObj;
- return accObj.Id;
- }
- @HttpGet
- global static Account doGet() {
- RestRequest request = RestContext.request;
- RestResponse response = RestContext.response;
- String accountId = request.requestURI.substring(request.requestURI.lastIndexOf('/')+1);
- Account acc= [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
- return acc;
- }
- }
- HttpRequest req = new HttpRequest();
- req.setHeader('Authorization', 'OAuth ' + accessToken);
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement