0

I am trying to run the below trigger in a custom object but getting the below error. Please help me

Error: Compile Error: Variable does not exist: ID__C at line 8 column 3

trigger AfterInsert on Status__c (before insert, Before update, after insert) {
    For (Status__c A:Trigger.New){
        A.Phone__c='91'+A.Phone__c;
        Case C=New Case();
        C.Subject='Case Raised';
        C.Priority='Low';
        C.ID__C='A.ID';//error is here
        insert C;
    }
}
2
  • Welcome to Salesforce Stack Exchange! Can you share what you are trying to achieve with the trigger? There are a number of things that can and should be improved to your code. Commented Jun 14, 2017 at 7:36
  • @Samir I am trying to insert & update a record in custom object Status and simultaneously update the case ID (in Case) for the new record created in Status
    – Avishek
    Commented Jun 14, 2017 at 23:35

1 Answer 1

2
trigger AfterInsert on Status__c (After update, After insert) { 
   List<case>caseList = new List<case>(); 
   for (Status__c a:Trigger.New){ 
        a.Phone__c = '91'+a.Phone__c; 
        Case c = New Case(); 
        c.Subject = 'Case Raised'; 
        c.Priority = 'Low'; 
        c.ID__ C= a.ID; 
        caseList.add(c);
     }
   insert caseList; 
}

You cannot have access to the IDs in before trigger. This trigger should work on after clause. Treating the ID__c as a lookup field to Status__c object i have edited your code.Also inserting in a loop is not a good practice. While a bulk operation your code will fail. Please try it and let me know it it works out for you or not.

2
  • I was in a perception that it is best to use one trigger per object hence was trying to insert all the possible events .
    – Avishek
    Commented Jun 14, 2017 at 23:46
  • Please correct me if I am wrong and kindly guide me as my requirement is to Insert a new record & update record in custom object Status and simultaneously update the case ID (in Case) for the new record created in Status. Itried running the above code but below is the error - Error: Compile Error: Duplicate variable: C at line 9 column 16
    – Avishek
    Commented Jun 14, 2017 at 23:49

You must log in to answer this question.

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