function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Théo ZANCHIThéo ZANCHI 

Flow or process creating a Folder in Google Drive team Drive

Hello Traiblazers ! 
I would like to create a flow that would, when an opportunity is closed won, create a new folder inside a google team drive for us to later automatically store relevant documents about this opportunity.
Do you know if this is feasable in Salesforce and if so, how ? Is this something that you have built in your orgs?
Many thanks
karthikeyan perumalkarthikeyan perumal
Hello, 

Yes, That can be achieved using google drive API + Apex Callouts and Rest/SOAP apis.
Depending on the size and deefault architecture of the company an ESB would be in place too...

GoogleAPI:
'https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=true

sample Code: 

This code is adding file in to spacific folder. 
 
public  void CreateFile(){
       String boundary = '----------9889464542212';
       String delimiter = '\r\n--' + boundary +'\r\n';
       String close_delim = '\r\n--' + boundary + '--';
       ApexPages.PageReference report = new ApexPages.PageReference('https://cs2.salesforce.com/00OR0000001FMn2?export=0&enc=UTF-8&xf=csv');
       
       String before='';      
       //Get the folder ID having file
       Google_Drive_Info__c g=new Google_Drive_Info__c();
       g=[SELECT Folder_Id__c FROM Google_Drive_Info__c WHERE Name=:'main'];
       String FolderId=g.Folder_Id__c; 
       
       // create a blob from our parameter value before we send it as part of the url
       Blob beforeblob = Blob.valueOf(before);
       String bodyEncoded = EncodingUtil.base64Encode(beforeblob);
       String filename='Sample_fileNameWithoutExtension';
       String filetype='text/csv';
       String body=delimiter+'Content-Type: application/json\r\n\r\n'+'{ "title" : "'+ filename+'",'+ ' "mimeType" : "'+ filetype+ '",' + '"parents":[{"id":"'+ FolderId +'"}] }'+delimiter+'Content-Type: ' + filetype + '\r\n'+'Content-Transfer-Encoding: base64\r\n'+'\r\n'+bodyEncoded+close_delim;
       Http http = new Http();
       HttpRequest req = new HttpRequest();
       req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=true');
       req.setHeader('Authorization', 'Bearer ' +access_token);
       req.setHeader('Content-Type', 'multipart/mixed; boundary="'+boundary+'"');
       req.setHeader('Content-length', String.valueOf(body.length()));
       req.setBody(body);
       req.setMethod('POST');
       req.setTimeout(60*1000);
       HttpResponse resp = http.send(req);
       filetype='';
       filename='';
   }

hope this will give you some idea to gohead with your task. 

Thanks
karthik