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
Mansi Mehta 65Mansi Mehta 65 

how to Write an Apex class which, in for loop, makes a callout to Google.com and insert responses as tasks on a specified Account recordand sends an email to a public group (Hardcode this too). T

Write an Apex class which, in for loop, makes a callout to Google.com and insert responses as tasks on a specified Account record (Hardcode this) and sends an email to a public group (Hardcode this too). There should be a method which accepts a list of accounts to be traversed
 
Correct limit checks are added to the code to avoid failure.
Code is written in bulk friendly manner.
Tasks are getting created on the Accounts and Email is sent out correctly to the public group members.
 
Best Answer chosen by Mansi Mehta 65
AnudeepAnudeep (Salesforce Developers) 
This isn't an exact code but serves as a sample 
 
public with sharing class GoogleWebService {
      
    public static Http http = new Http();
    public static HTTPResponse response;
    public static HttpRequest request;
 
    public static void getProfile(String userEmail) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/gmail/v1/users/' + userEmail + '/profile');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getUserDrafts(String userEmail) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/gmail/v1/users/' + userEmail + '/drafts');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getMyCalendar() {
         
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/calendar/v3/users/me/calendarList');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getFile(String fileId) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/drive/v3/files/' + fileId);
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
}

To test this code, run the following snippet from execute anonymous window 
 
GoogleWebService.getProfile('youremail@gmail.com');
GoogleWebService.getUserDrafts('youremail@gmail.com');
GoogleWebService.getMyCalendar();
GoogleWebService.getFile('fileId');

 

All Answers

AnudeepAnudeep (Salesforce Developers) 
This isn't an exact code but serves as a sample 
 
public with sharing class GoogleWebService {
      
    public static Http http = new Http();
    public static HTTPResponse response;
    public static HttpRequest request;
 
    public static void getProfile(String userEmail) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/gmail/v1/users/' + userEmail + '/profile');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getUserDrafts(String userEmail) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/gmail/v1/users/' + userEmail + '/drafts');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getMyCalendar() {
         
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/calendar/v3/users/me/calendarList');
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
 
    public static void getFile(String fileId) {
 
        request = new HttpRequest();
        request.setMethod('GET');
        request.setEndpoint('callout:GoogleAPI/drive/v3/files/' + fileId);
 
        response = http.send(request); 
 
        System.debug(response.getBody());
    }
}

To test this code, run the following snippet from execute anonymous window 
 
GoogleWebService.getProfile('youremail@gmail.com');
GoogleWebService.getUserDrafts('youremail@gmail.com');
GoogleWebService.getMyCalendar();
GoogleWebService.getFile('fileId');

 
This was selected as the best answer
Mansi Mehta 65Mansi Mehta 65
This somewhat helped to proceed. Thanks Anudeep
AnudeepAnudeep (Salesforce Developers) 
You are welcome, Mansi. I appreciate if you can close the query by marking it as solved. It may help others in the community. Thank You!