0

I'm very new to coding. Can you help me out with the following error?

Error: Compile Error: No such column 'UniqueID' on entity 'Relationship__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 15 column 52

The field does exist in the Relationship object and its API name is UniqueID__C.

Here's the code:

trigger RelationshipReverseRecord on Relationship__c (before insert, before update, before delete)
{
    if(Trigger.isInsert)
    {
        Set<string> rIDs = new Set<string>();
        for(Relationship r : Trigger.New)
        {
            String uID = r.parentID + r.childID;
            String rID = r.childID + parentID;
            r.UniqueID__c = uID;
            r.ReverseID__c = rID;
            rIDs.add(rID);
        }
    }
    List<Relationship__c> existingReverseRecords = [SELECT UniqueID, Reverse_Record__c FROM Relationship__c WHERE ID IN : rIDs];
    List<Relationship__c> newReverseRecords = new List<Relationship__c>();
    for(Relationship__c new R : Trigger.New)
    {
        if(newR.ReverseID__c == existingR.UniqueID__c)
        {
            found = true;
            break;
        }
    }
    if(found==false && newR.ReverseRecords)
    {
        Relationship__c newReverse = new Relationship__c(ReverseRecord__c = true, Parent__c = new R.Child__c);
        newReverse.Child__c = newR.Parent__c;
        newReverseRecords.add (newReverse);
    }
}

insert newReverseRecords;
  • Your query to existingReverseRecords is attempting to access UniqueID and not UniqueID__c. – TSmith Mar 14 '17 at 13:08
2

You are using the right field two lines after the error thrown. And this error is easily understandable.

In your query, you select the field without adding the suffix.

Also, your insert clause is outside your trigger.

Finally, you instantiate your rIDs list outside its scope.

Here's the right code:

trigger RelationshipReverseRecord on Relationship__c (before insert, before update, before delete)
{
    Set<string> rIDs = new Set<string>();

    if(Trigger.isInsert)
    {
        for(Relationship r : Trigger.New)
        {
            String uID = r.parentID + r.childID;
            String rID = r.childID + parentID;
            r.UniqueID__c = uID;
            r.ReverseID__c = rID;
            rIDs.add(rID);
        }
    }
    List<Relationship__c> existingReverseRecords = [SELECT UniqueID__c, Reverse_Record__c FROM Relationship__c WHERE ID IN : rIDs];
    List<Relationship__c> newReverseRecords = new List<Relationship__c>();
    for(Relationship__c new R : Trigger.New)
    {
        if(newR.ReverseID__c == existingR.UniqueID__c)
        {
            found = true;
            break;
        }
    }
    if(found==false && newR.ReverseRecords)
    {
        Relationship__c newReverse = new Relationship__c(ReverseRecord__c = true, Parent__c = new R.Child__c);
        newReverse.Child__c = newR.Parent__c;
        newReverseRecords.add (newReverse);
    }

    insert newReverseRecords;
}
  • Thank you for your help! I do see now that that was a really easy error ha. One more question for you. My next error is Error: Compile Error: unexpected token: insert at line 33 column 0 Am I not supposed to insert said records at that point? – user42632 Mar 14 '17 at 14:03
  • This is just because you call your insert outside the trigger perimeter. Move your insert clause before the bracket closing the trigger (i.e. 3 lines before). – Martin Lezer Mar 14 '17 at 14:07
  • Thank you again! Can you tell me why it's saying rIDs doesn't exist? Error: Compile Error: Variable does not exist: rID at line 15 column 126 – user42632 Mar 14 '17 at 14:33
  • I updated my answer to include the whole code. – Martin Lezer Mar 14 '17 at 14:37
  • I tried that, thank you for fixing the errors for me. I'm getting an error that says: Error: Compile Error: Variable does not exist: found at line 22 column 13. It's referring to the found=true line. – user42632 Mar 14 '17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.