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;
    }
}
  • 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. – Guy Clairbois Jun 14 '17 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 Jun 14 '17 at 23:35
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.

  • 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 Jun 14 '17 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 Jun 14 '17 at 23:49

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.