function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Class to perform Callout ============================ public class BoxController { public static string clientid; public static string clientsecret; public static string redirecturi; public static string code; public static string jsonresponse; public static string accessToken; public static string ViewAPI_Key; public static string RefreshToken; public static string jsonFolderResponse; public static string jsonFolderResponse1; public static string jsonItemsResponse; public static string folderId; public static String FileViewUrl; public static String securitycode; public static string box_login; public integer i=0; public BoxController() { //redirecturi='https://na30.salesforce.com/apex/boxresponse2'; /* clientid=BoxCCredentials__c.getValues('CredentialsBox').Client_Id__c; clientsecret=BoxCCredentials__c.getValues('CredentialsBox').Client_Secret__c; ViewAPI_Key=BoxCCredentials__c.getValues('CredentialsBox').View_API_Key__c; AccessToken=BoxCCredentials__c.getValues('CredentialsBox').Access_Token__c; RefreshToken=BoxCCredentials__c.getValues('CredentialsBox').Refresh_Token__c; system.debug('Client_Id__c'+clientid); system.debug('clientsecret'+clientsecret); system.debug('clientsecret'+ViewAPI_Key); system.debug('clientsecret'+AccessToken);*/ } @future(callout=true) public static void boxAuthentication(string aid) { try { String endpointUrl1='https://app.box.com/api/oauth2/authorize?response_type=code&client_id='+clientid+'&state=symcsk02&box_login=boxpocintegration@gmail.com'; redirecturi='https://na30.salesforce.com/boxresponse2'; code=ApexPages.currentpage().getparameters().get('code');// Attempt to dereference null object at commented line in boxcontroller class securitycode=ApexPages.currentPage().getparameters().get('state'); // clientid=BoxCCredentials__c.getValues('CredentialsBox').Client_Id__c; clientsecret=BoxCCredentials__c.getValues('CredentialsBox').Client_Secret__c; ViewAPI_Key=BoxCCredentials__c.getValues('CredentialsBox').View_API_Key__c; AccessToken=BoxCCredentials__c.getValues('CredentialsBox').Access_Token__c; RefreshToken=BoxCCredentials__c.getValues('CredentialsBox').Refresh_Token__c; system.debug('Client_Id__c'+clientid); system.debug('clientsecret'+clientsecret); system.debug('clientsecret'+ViewAPI_Key); system.debug('clientsecret'+AccessToken); HttpRequest request=new HttpRequest(); request.setendpoint('https://api.box.com/oauth2/token'); request.setmethod('POST'); string body='grant_type=authorization_code&'; body=body+'box_login'+box_login; body=body+'code='+code; body=body+'&client_id='+clientid; body=body+'&client_secret='+clientsecret; request.setBody(body); Http p=new Http(); HttpResponse response=p.send(request); jsonresponse=response.getBody(); fromJSON js=(fromJSON)JSON.deserialize(jsonresponse,fromJSON.class); accessToken=js.access_token; system.debug('accessToken' +accessToken); system.debug('code is '+code); HttpRequest request1=new HttpRequest(); request1.setendpoint('https://api.box.com/2.0/folders'); request1.setmethod('POST'); request1.setHeader('Authorization','Bearer ' + accessToken); string bbody='{"name":"a.name", "parent": {"id": "0"}} '; request.setBody(bbody); Http p1=new Http(); HttpResponse response1=p1.send(request1); jsonFolderResponse=response1.getBody(); system.debug('jsonFolderResponse'+jsonFolderResponse1); } catch (exception ex) { system.debug('ex '+ex.getMessage()+' '+ex.getLineNumber()); } } public class fromJSON { public string access_token; public integer expires_in; public cls_restricted_to[] restricted_to; public string refresh_token; } class cls_restricted_to { } } ================== class which calls authorize page public class WebserviceBox { public string clientid; public string code; public string AutorizeBox() { clientid=BoxCCredentials__c.getValues('CredentialsBox').Client_Id__c; String endpointUrl1='https://app.box.com/api/oauth2/authorize?response_type=code&client_id='+clientid+'&state=symcsk02'; pageReference pag=new pageReference(endpointUrl1); pag.setRedirect(true); return endpointUrl1; } public void restCode(){ code=ApexPages.currentpage().getparameters().get('code'); } } =========================== trigger for which calls the class trigger BoxInsert on Account (after insert) { for(account a:trigger.new) { try { WebserviceBox wc=new WebserviceBox(); string code=wc.AutorizeBox(); system.debug('code ' + code); BoxController.boxAuthentication(a.id); } catch (exception ex) { system.debug('ex '+ex.getMessage()+' '+ex.getLineNumber()); } } } ================================ errror: Attempt to dereference null object at commented line in boxcontroller class
You can try the code as mentioned in the below blogs,
https://developer.salesforce.com/forums/?id=906F0000000DCBBIA4
https://salesforce.stackexchange.com/questions/118710/create-box-folder-via-apex
I hope it will help you for sure.
If it does, please mark as Best Answer to help others too.
Thanks.
Thanks for the Quick replay
I tried those but I need multiple folders on box
Thanks
thanks for replay
it's not working
thanks