+ Start a Discussion

many to many relationships

    I am having problems setting my many-to-many relationship. Right now I am using the enterprise.wsdl and writing in Java (I could  do it in Apex too, it really makes no difference). I have a custom object called Reject_Codes__c. On opportunity can have multiple reject codes, and likewise a reject code will link to many opportunities. I went into my reject object and created a lookup relationship to opportunity


Child Relathionship Name: RejectCodes
Related List Label : Reject Codes

and on opportunity

        <label>Reject Code</label>

Child Relathionship Name: Opportunities
Related List Label : Opportunities

to test it I am trying :

          Opportunity opp = ....
          Reject_Code_Maintenance__c obj = new Reject_Code_Maintenance__c();
          Reject_Code_Maintenance__c obj2 = new Reject_Code_Maintenance__c();
          QueryResult qr = new QueryResult();
          obj.setReject_Code__c("88");   // this is the external id -- note that first I tried using the salesforce Id using setId, but the api puked on this saying that Id wasn't indexed WTF?

          SObject[] aa = new SObject[]{obj, obj2};
          conn.update(new SObject[]{opp});

and I get the following :

 faultString: INVALID_FIELD: No such column 'RejectCodes__r' on entity 'opportunity'.

even though the enterprise.wsdl had the appropriate method (setRejectCodes__r(QueryResult qr))

What am I doing wrong please?

Best Answer chosen by Admin (Salesforce Developers) 
The fact that its called QueryResult should of been a hint, those fields exist for query only. You need to pass your obj,obj2 instances directly to the create call, having first set their Opportunity__c value.