You need to sign in to do that
Don't have an account?

Variable does not exist: c.id
hello all
im trying to update a lookup field in the acct with the case id but i keep getting the error variable does not exist, ay help will be appreciate
by the way im new to this apex code and im kind rusty after 10 years i didn’t to programming at all
trigger updateAccountWithCase on Case (after insert) {
set <ID> acc_ids = new set <id> ();
for (case c : trigger.new)acc_ids.add(c.accountid);
list<account> acct_to_update = [select id, case__c from account where id in :acc_ids];
{
for (account acc: acct_to_update) acc.case__c = caseid;
update acct_to_update;
}
}
try this
Dharmesh
thanks a lot for your quick reply
i copy and past what you post and im getting this
Error: Compile Error: unexpected token: 'List' at line 6 column 8
thanks again for your help
try this
Error: Compile Error: Variable does not exist: caseid at line 8 column 27
i got this one this time
Hi,
Try this out:
But I wanted to clarify, is this a bulk enabled trigger?
If yes, whout should happen if the same accountId is associated with various cases???
Can you explain the scenario and purpose of your trigger??
I just hope, this is what you were looking out for.
Correct me If I am wrong in understanding your Scenario. From my understanding if you are trying to update the field on the Account object after the case is inserted try the following code
trigger updateAccountWithCase on Case (after insert) {
public Id caseId;
public Id aId;
for(Case c : Trigger.new){
caseId = c.Id; //get the case Id of the new inserted record
}
List<Case> cList = [select Account__c from case where Id =:caseId];
for(Case accCase : cList){
aId = accCase.Account__c; //get the account Id of the new case
}
List<Account> acc = [select Id from Account where Id=:aId];
for(Account a : acc){
//update the field you wish to update on the Account object for example a.<fieldname> = <some value>
update a;
}
}
Hope this help you..........