You need to sign in to do that
Don't have an account?
pdo
Error On Trigger
Hi All,
I am geeting the following error on my trigger and cannot figure out why I am getting it. Can anyone help?
trigger wfcallupdate on Case (after insert) { //Declare Variable public set<id> caseid = new set<id>(); public set<id> oppid = new set<id>(); public list<opportunity> opptoupdate = [select id from opportunity where id in :oppid]; if(Trigger.isInsert){ for(case c: Trigger.new){ if(c.recordtype.name == 'Workflow') oppid.add(c.opportunity__r.id); caseid.add(c.id); } } //Update Opportunity if(oppid.size()>0){ for(opportunity o: [Select id, workflow_case__c from opportunity where id in :oppid]) opptoupdate.add(new opportunity(id=o.id, workflow_case__c=caseid)); } update opptoupdate; }
Error: Compile Error: Invalid initial expression type for field Opportunity.Workflow_Case__c, expecting: Id at line 18 column 63 |
Your logic is pretty far off-base; I'm actually having a hard time even understanding what your code is attempting to do.
Let me see if I have this right:
Opportunity: Workflow_Case__c (Lookup: Case)
Case: Opportunity__c (Lookup: Opportunity)
Each Opportunity would have one case known was the Workflow Case, which in turn would have its reference on the case, stored in Opportunity__c, making a strict 1:1 relationship.
Assuming this is what you are indeed after, you might need some validation logic to enforce the 1:1 relationship. Other than that, you'll need to use a Map, not a Set, to track these related records and perform the requisite updates.
The process would be as follows:
Map the Opportunity Id to the Case Id.
Query all opportunities, and update the Workflow_case__c field.
Save the changes.
I'm ignoring the situation of a 1:n relationship sneaking in and mucking up your data, but this is basically it. You don't need to check the record type unless Opportunity__c is used in more than one place; it would suffice to simply make a system validation rule that forces this field to be empty if the wrong record type is used.
All Answers
Your logic is pretty far off-base; I'm actually having a hard time even understanding what your code is attempting to do.
Let me see if I have this right:
Opportunity: Workflow_Case__c (Lookup: Case)
Case: Opportunity__c (Lookup: Opportunity)
Each Opportunity would have one case known was the Workflow Case, which in turn would have its reference on the case, stored in Opportunity__c, making a strict 1:1 relationship.
Assuming this is what you are indeed after, you might need some validation logic to enforce the 1:1 relationship. Other than that, you'll need to use a Map, not a Set, to track these related records and perform the requisite updates.
The process would be as follows:
Map the Opportunity Id to the Case Id.
Query all opportunities, and update the Workflow_case__c field.
Save the changes.
I'm ignoring the situation of a 1:n relationship sneaking in and mucking up your data, but this is basically it. You don't need to check the record type unless Opportunity__c is used in more than one place; it would suffice to simply make a system validation rule that forces this field to be empty if the wrong record type is used.
You're awesome! I had to make one small modification so I wouldn't get the Compile Error: Initial term of field expression must be a concrete SObject: LIST<Opportunity>