0

In our org, we have a custom object Relationship and each Relationship ties two Person Accounts together. I am trying to update a custom field UniqueID, which combines both Person Accounts' IDs together, and then update another custom field ReverseID, which is just the Person Accounts IDs, just switched in orders.

An example of a Unique ID would be 001G000001zPkCCAAA001G000001zPkBsAAB which is a combination of two account records. The Reverse ID would be 001G000001zPkBsAAB001G000001zPkCCAAA.

I am trying to accomplish the example above through Apex, but I am getting multiple errors. Being fairly new to Apex & Triggers, any guidance would be greatly appreciated!

    trigger RelationshipReverseRecord on Relationship (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> existing ReverseRecords = [SELECT UniqueID, Reverse_Record__c FROM Relationship__c WHERE ID IN : rIDs0];
    List<Relationship> new Reverse Records = new List<>();
    for(Relationship__c new R : Trigger.New)
    {
        if(new R.ReverseID__c == existing R.UniqueID__c)
        {
            found = true;
            break;
        }
    }
    if(found==false && new R.ReverseRecord)
    {
        Relationship__c new Reverse = new Relationship__c(ReverseRecord__c = true, Parent__c = new R.Child__c);
        new Reverse.Child__c = new R.Parent__c;
        new ReverseRecords.add (new Reverse);
    }
}

insert newReverseRecords;
8
  • Please edit your post to actually contain a sentence that is a question. As it stands, it is not clear what you are asking.
    – Adrian Larson
    Mar 8, 2017 at 16:20
  • Adrian just updated :)
    – B Wayne
    Mar 8, 2017 at 16:35
  • Better, but still does not contain a question. What are you asking?
    – Adrian Larson
    Mar 8, 2017 at 16:36
  • @Sutha - I still don't see a question
    – Eric
    Mar 8, 2017 at 16:36
  • Sorry I am not having the greatest time explaining myself. Pretty much I am trying to accomplish what is in the example
    – B Wayne
    Mar 8, 2017 at 16:38

1 Answer 1

1

Seems this

List<Relationship> new Reverse Records = new List<>();

Should be removed as it is defined on the line above it not to mention it is syntactically incorrect or change it to

 List<Relationship__c> newReverseRecords = new List<Relationship__c>();

And

 List<Relationship__c> existing ReverseRecords

Should be

List<Relationship__c> existingReverseRecords

You must log in to answer this question.

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