2013-06-10 4 views
4

나는 영업 인력에 대한 데이터를 업로드하고 내가 자식 개체에 대해 하나 개의 조회 필드가 두 개의 종속 객체가 SF 객체 에 저장 비누 API를 사용하여 세일즈 포스 파트너 WSDL을 사용하고영업 인력은

때 종속 개체 데이터를 저장하려고하는 부모 개체를 저장하려고합니다.

어떻게 SOAP API를 사용하여이를 수행 할 수 있습니까? 당신은 그 API를 먼저 마스터 객체를 생성해야하기 때문에 당신이 ID를 아이가 개체를 설정하는 얻을 수 있도록이는 SOAP API를 사용하여 달성 할 수

답변

1

사전에

감사합니다 .. . 하나의 트랜잭션에서 모든 객체를 생성하려면 expose an Apex method as a SOAP web service을 호출해야합니다.

+0

많은 자식 개체에 대해 내 대답은 여전히 ​​적용되지만 아래의 답변은 단일 수준의 계층에 비해 월등히 우수합니다. –

2

부모 개체 유형에 외부 ID 필드를 사용하여 SOAP에서이 작업을 수행 할 수 있습니다.이 작업을 통해 단일 호출로 상위 & 자식 개체를 보내고 외부 ID 필드 값을 통해 자동으로 연결할 수 있습니다.

여기에 계정과 관련 연락처를 한 번에 만드는 Java의 샘플이 있습니다. 연락처는 extId__c 필드를 통해 계정과 관련됩니다. 내가이 프로그램을 실행할 때

public static void main(String[] args) throws Exception { 

    // login to salesforce. 
    PartnerConnection pc = Connector.newConnection(args[0], args[1]); 

    // The new Account record we're going to create. 
    SObject acc = new SObject(); 
    acc.setType("Account"); 
    acc.setField("Name", "My New Account"); 
    acc.setField("extId__c", UUID.randomUUID().toString()); 

    // The new Contact record we're going to create. 
    SObject con = new SObject(); 
    con.setType("Contact"); 
    con.setField("FirstName", "Simon"); 
    con.setField("LastName", "Fell"); 
    // This Account object we build with the relationship to the account above based 
    // on the extId__c field, and then we set it on the contact record 
    // this is the standard FK lookup using ExternalIds feature. 
    SObject parentAcc = new SObject(); 
    parentAcc.setType("Account"); 
    parentAcc.setField("extId__c", acc.getField("extId__c")); 
    con.setField("Account", parentAcc); 


    // Now we can insert both records at once 
    SaveResult [] sr = pc.create(new SObject [] { acc, con}); 
    printSaveResult("Account result", sr[0]); 
    printSaveResult("Contact result", sr[1]); 
} 

private static void printSaveResult(String label, SaveResult sr) { 
    if (sr.isSuccess()) 
     System.out.println(label + " success recordId is " + sr.getId()); 
    else 
     System.out.println(label + " failed, reason is " + sr.getErrors()[0].getMessage()); 
} 

, 그것은

Account result success recordId is 0013000001DFMRxAAP 
Contact result success recordId is 0033000001aEgskAAC 

를 인쇄 그리고 내가 웹 응용 프로그램에 로그인 할 때, 난 내 새 계정 기록을 볼 수 있으며, 관련 목록에서 자식 연락처 레코드. enter image description here