superfell / zkSforce

Cocoa library for calling the Salesforce.com Web Services API
https://pocketsoap.com/osx/zksforce/
MIT License
76 stars 27 forks source link

criteria based sharing via SOAP. Is it actually possible? #13

Closed johndpope closed 10 years ago

johndpope commented 10 years ago

Do you know the answer to this question? I've updated your code to hit the soap end point - but it conks out. Any ideas?

http://salesforce.stackexchange.com/questions/17481/create-ownersharingrule-via-salesforce-metadata-api

inside zkSforceClient

- (NSDictionary *)createSharingRule{

    if (!authSource) return nil;
    [self checkSession];
    /*
     <?xml version="1.0" encoding="UTF-8"?>
     <AccountSharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
     <criteriaBasedRules>
     <fullName>20601Rule</fullName>
     <name>20601Rule</name>
     <sharedTo>
       <group>20601</group>
     </sharedTo>
     <criteriaItems>
         <field>Territory__c</field>
         <operation>equals</operation>
         <value>20601</value>
     </criteriaItems>
     <accountAccessLevel>Edit</accountAccessLevel>
     </criteriaBasedRules>
     </AccountSharingRules>*/

    ZKGenericEnvelope *env = [[[ZKGenericEnvelope alloc] initWithSessionAndMruHeaders:[authSource sessionId] mru:NO clientId:clientId namespaceUri:@"http://soap.sforce.com/2006/04/metadata" prefix:@"met"] autorelease];

    //create
        [env startElement:@"met:create"];
    [env addElement:@"met:asOfVersion" elemValue:[NSNumber numberWithInt:preferedApiVersion]];

    [env startElement:@"met:accountSharingRules"];
    [env startElement:@"met:criteriaBasedRules"];
    [env addElement:@"met:fullName" elemValue:@"20601"];
    [env addElement:@"met:name" elemValue:@"20601"];
    [env startElement:@"met:sharedTo"];
    [env addElement:@"met:group" elemValue:@"20601"];
    [env endElement:@"met:sharedTo"];
    //criteriaItems
    [env startElement:@"met:criteriaItems"];
    [env addElement:@"met:field" elemValue:@"Territory__c"];
    // <operation>equals</operation>
       [env addElement:@"met:operation" elemValue:@"equals"];
    [env addElement:@"met:value" elemValue:@"20601"];
    [env endElement:@"met:criteriaItems"];
    //  <accountAccessLevel>Edit</accountAccessLevel>
    [env addElement:@"met:accountAccessLevel" elemValue:@"Edit"];
    [env endElement:@"met:criteriaBasedRules"];
    [env endElement:@"met:accountSharingRules"];
    [env endElement:@"met:create"];
    [env endElement:@"s:Body"];
    NSDictionary *dict  = [self fireMetaDataRequest:[env end]];

    return dict;
}
superfell commented 10 years ago

Sorry, don't know and unless you think this is from some bug in zkSforce, is not really relevant here, am closing.