1

I am trying to set the value of one object in a custom object to be the same as the value of another object before deleting the first object. When I use the assignment operator, nothing happens although I'm certain that the Account__r of dbc is populated. Does anybody know why this doesn't work?

for ( Customer__c dbc : [SELECT Account__c, Account__r.Priority__c, Unique_Id__c FROM Customer__c WHERE Unique_Id__c IN :customers.keySet( )])
        {
            Customer__c c    = customers.get( dbc.Unique_Id__c );
            // replace the account of the last added customer if the priority is less
            // than that of the previous entry   
            // I could not find the solution to this problem. I cannot access
            // c.Account__r.Priority__c without using a DB call and could find no solution online.
            if ( accountMap.get( c.Account__c ).Priority__c.compareTo( dbc.Account__r.Priority__c ) 
                 < 0 )
            {
                c.Account__r = dbc.Account__r;
            }
            entriesToBeDeleted.add( dbc );
        }

thanks in advance

3
  • why are you using < 0 in the compareTo(..) method? This doesn't test for equality; it tests for lexicographically precedes.
    – cropredy
    Commented Sep 10, 2014 at 21:08
  • Yes, I'm trying to do that :) thanks. Also I found my solution (for future references): c.Account__r = dbc.Account__r; should be: c.Account__c = dbc.Account__r.Id; Commented Sep 10, 2014 at 21:12
  • yes, of course -- good work
    – cropredy
    Commented Sep 10, 2014 at 21:13

1 Answer 1

4

Instead of using the c.Account__r, I should have used c.Account__c and I also should have used the c.Account__r.Id rather than c.Account__r.

c.Account__r = dbc.Account__r;

should be

c.Account__c = dbc.Account__r.Id;

maybe someone else is also struggling with this.

1
  • Jør, know that you should also be able to accept your own answer. This can be done by checking the (V) button on the left of your answer. Commented Oct 7, 2014 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .