【发布时间】:2022-01-17 13:54:52
【问题描述】:
我需要用这个 Apex 类制作一个 Lightning Web 组件,但我不知道如何将数据传递给 JS 和 HTML,以及如何创建该 lwc。我想制作一个 lwc,显示每次使用/调用 lwc 组件时从某个电子邮件收到的每封电子邮件。也许做一个光环组件更好?我不知道。这是代码
public with sharing class Gmail {
public with sharing class GMResponseMessages {
public Integer resultSizeEstimate;
public GMThread[] messages;
}
public with sharing class GMThread {
public String id;
public String threadId;
}
public with sharing class GMMessage {
public String id;
public String threadId;
public String[] labelIds;
public String snippet;
public String historyId;
public String internalDate;
public GMMessagePart payload;
public String sizeEstimate;
public String raw;
}
public with sharing class GMMessagePart {
public String partId;
public String mimeType;
public String filename;
public Header[] headers;
public GMMessagePartBody[] body;
public GMMessagePart[] parts;
}
public with sharing class Header {
public String name;
public String value;
}
public with sharing class GMMessagePartBody {
public String attachmentId;
public String superinteger;
public String data;
}
@AuraEnabled
public static void getGmail_API() {
//GET https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/{id}
Http http = new Http();
HTTPResponse response;
HttpRequest request;
String userEmail = 'myemail@gmail.com';
request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint('callout:Gmail_API/gmail/v1/users/myemail@gmail.com/messages?q=from:othermail@mail.it');
response = http.send(request);
System.debug('START');
System.debug(response.getStatusCode());
if(response.getStatusCode() == 200) {
JSONParser parser = JSON.createParser(response.getBody());
System.debug(parser);
GMResponseMessages jsonResponse = (GMResponseMessages)JSON.deserialize(response.getBody(), GMResponseMessages.class);
System.debug(jsonResponse);
for(GMThread thread: jsonResponse.messages){
System.debug('THREAD FOR');
System.debug(thread);
Http httpMsg = new Http();
HTTPResponse responseMsg;
HttpRequest requestMsg;
requestMsg = new HttpRequest();
requestMsg.setMethod('GET');
requestMsg.setEndpoint('callout:Gmail_API/gmail/v1/users/myemail@gmail.com/messages/' + thread.id);
responseMsg = httpMsg.send(requestMsg);
if(responseMsg.getStatusCode() == 200) {
GMMessage jsonResponseMsg = (GMMessage)JSON.deserialize(responseMsg.getBody(), GMMessage.class);
System.debug(jsonResponseMsg);
}
}
}
}
}
【问题讨论】:
标签: gmail salesforce apex salesforce-lightning lightning