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;