Skip to content

Instantly share code, notes, and snippets.

View A-pZ's full-sized avatar

A-pZ A-pZ

  • Capybara(Oni-Tenjiku-nezumi)
  • Tokyo, shinagawa
View GitHub Profile
@A-pZ
A-pZ / CompanyQueryRepository.java
Created August 7, 2023 09:49
Bulk API 2.0で登録したクエリの結果を取得する
package com.github.apz.salesforcesample.repository;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.github.apz.salesforcesample.config.SalesforceProperties;
import com.github.apz.salesforcesample.model.AuthenticationResult;
import com.github.apz.salesforcesample.model.Company;
import lombok.AllArgsConstructor;
import lombok.Getter;
@A-pZ
A-pZ / CompanyQueryRepository.java
Last active March 12, 2024 02:50
Bulk API 2.0を使ったクエリの登録
package com.github.apz.salesforcesample.repository;
import com.github.apz.salesforcesample.config.SalesforceProperties;
import com.github.apz.salesforcesample.model.AuthenticationResult;
import com.github.apz.salesforcesample.model.Company;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Repository;
@A-pZ
A-pZ / CompanyRepository.java
Created August 7, 2023 04:21
登録した取引先を検索する
public Company find(String objectId, AuthenticationResult authenticationResult) {
Company result = salesforceWebClient.get()
.uri( salesforceProperties.getApplicationPath()+ "/sobjects/Account/" + objectId) // 作成した取引先のオブジェクトid
.header("Authorization", authenticationResult.bearerToken())
.retrieve()
.bodyToMono(Company.class)
.block();
log.info("result :{}", result);
return result;
}
@A-pZ
A-pZ / CompanyRepository.java
Created August 7, 2023 02:51
取引先の削除処理
public void delete(String objectId, AuthenticationResult authenticationResult) {
salesforceWebClient.delete() // 削除はDELETE
.uri( salesforceProperties.getApplicationPath()+ "/sobjects/Account/" + objectId) // 更新同様、削除するオブジェクトIDを指定
.header("Authorization", authenticationResult.bearerToken())
.retrieve()
.bodyToMono(Company.class)
.block();
}
@A-pZ
A-pZ / CompanyRepository.java
Created August 7, 2023 02:37
取引先の更新処理
public void update(String objectId, Company company, AuthenticationResult authenticationResult) {
salesforceWebClient.patch() // 更新はPATCH
.uri( salesforceProperties.getApplicationPath()+ "/sobjects/Account/" + objectId) // 更新対処の取引先のオブジェクトIDを指定
.header("Authorization", authenticationResult.bearerToken()) // 認証結果
.contentType(MediaType.APPLICATION_JSON)
.body(Mono.just(company), Company.class).retrieve()
.toBodilessEntity()
.block();
}
@A-pZ
A-pZ / SalesforceRegisterTest.groovy
Last active August 7, 2023 02:03
取引先を新規登録するテストクラス
package com.github.apz.salesforcesample.repository
import com.github.apz.salesforcesample.model.Company
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification
@SpringBootTest
class SalesforceRegisterTest extends Specification {
@Autowired
@A-pZ
A-pZ / Company.java
Last active August 7, 2023 04:33
Salesforceの取引先を新規登録する
package com.github.apz.salesforcesample.model;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
@A-pZ
A-pZ / authentication_result.log
Created August 6, 2023 07:59
認証結果(AuthenticationResult)の出力例
INFO 14368 --- [ Test worker] c.g.a.s.r.SalesforceAuthentication :
result:
AuthenticationResult(
statusCode=0,
accessToken=**MASK**
signature=**MASK**,
instanceUrl=https://***********.salesforce.com,
id=https://test.salesforce.com/id/***************,
tokenType=Bearer,
issuedAt=1691308480245
@A-pZ
A-pZ / SalesforceAuthenticationTest.groovy
Created August 6, 2023 07:53
Salesforce認証のテスト
package com.github.apz.salesforcesample.repository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification
@SpringBootTest
class SalesforceAuthenticationTest extends Specification {
@Autowired
SalesforceAuthentication sut
@A-pZ
A-pZ / AuthenticationResult.java
Last active August 7, 2023 04:40
Salesforceの認証を行う
package com.github.apz.salesforcesample.model;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@NoArgsConstructor @Getter @Setter @ToString