function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hitee Bhasin 23Hitee Bhasin 23 

Compile error- don't understand the issue here?

I'm getting an error that doesn't seem like an error...Maybe there's something I'm not seeing. Relationship is a custom object, and it's API name is Relationship__c. Can anyone help? I'm fairly new to coding. Thank you!

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 + r.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 newR : 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 = newR.Child__c);
        newReverse.Child__c = newR.Parent__c;
        newReverseRecords.add (newReverse);
    }

    insert newReverseRecords;
}

Hitee Bhasin 23Hitee Bhasin 23
Sorry, here's the error::
Error: Compile Error: Invalid type: Relationship at line 7 column 13
AmrenderAmrender
Please use custom object's API name (Relationship__c instead Relationship) at line no 7

for(Relationship__c r : Trigger.New) 

Regards
Amrender
Hitee Bhasin 23Hitee Bhasin 23

Ah. Duh! Thank you, I can't believe I missed that. I have one more issue that I can't seem to figure out. 

 

Error: Compile Error: Variable does not exist: found at line 22 column 13 (It's referring to the line that says found = true). 

found is a custom field on the Relationship object. I tried editing the line to found__c = true and that didn't work either. It says:
Error: Compile Error: Variable does not exist: found__c at line 22 column 13. 

Any idea what I'm doing wrong here? I appreciate the help! Thank you again. 

AmrenderAmrender
If 'found' is a variable, it is not declared. Please declare it.

If found is a custom field use newR.found__c

Regards
Amrender