• Aviral Agrawal 26
  • NEWBIE
  • 0 Points
  • Member since 2018

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

hi there

have a piece of code

how to create csv file and name it?

 

public static void sheets (List<Opportunity> oppo){

        List<Opportunity > opps = [SELECT Id, Name, Description, CreatedDate, LastModifiedDate FROM Opportunity limit 10];
        string header = '"Record Id","Name","Description","Created Date","LastModifiedDate" \n';
        string finalstr = header ;
        for(Opportunity o: opps){
            
            string recordString = '"'+o.id+'","'+o.Name+'","'+o.Description+'","'+o.CreatedDate +'","'+o.LastModifiedDate+'"\n';
            
            finalstr = finalstr +recordString;
            
        }


        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint('callout:Googel_Sheets/upload/drive/v3/files');
        req.setHeader('Content-Type', 'multipart/mixed'); 
        req.setHeader('Content-length', String.valueOf(finalstr.length())); //required!!!!
        req.setTimeout(120000);
        req.setBody(finalstr);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug('RESPONSE   --->   '+res.getStatus());  System.debug('RESPONSE   --->   '+res.getBody());
        System.debug('req   --->   '+req);
        
        
    }

when i send it, in google i recive untitled file with unknown type
User-added image

may be any solutions without JSON???
thx
But it does! 
The only thing I can think of is when in Step 3: "Suggestion Name" Had to have an under score (_) between the words or it wouldn't accept it. Otherwise I followed the directions precisely... 
User-added image