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

Error: Compile Error: Incompatible key type SOBJECT:Visit__c for MAP<Id,Visit__c>
Hi team,
I am writing a trigger to update a field in Account object(PVF_value__c) . Account is having a Detail called Visit__c which has 2 fields Location__c (Acount) and Primary_visit_focus__c .
So whenever a visit is created on a account it should update the field in Account.
Below is the code and the error i am getting.
trigger Acct_pvf_value on Account (after insert,after update) {
for(Account acc :Trigger.new()){
List<String> IDpvf = new List<String>();
IDpvf.add(acc.ID);
Map<ID,Visit__c> VisMap = new Map<ID,Visit__c>([Select Location__c,Primary_Visit_Focus__c from Visit__c where Location__c in :IDpvf ]);
for(Visit__c visit : VisMap.keyset())
{
if(acc.id == VisMap.get(visit).Location__c){
acc.PVF_value__c= VisMap.get(visit).Primary_Visit_Focus__c;
}
update IDpvf;
}
}
}
Error: Compile Error: Incompatible key type SOBJECT:Visit__c for MAP<Id,Visit__c> at line 9 column 19
Any help on this is highly appreciated
May be you wanted to do
Earlier you just passed SObject instead of the Id
Error: Compile Error: Loop variable must be of type Id at line 6 column 14
trigger Acct_pvf_value on Account (after insert,after update) {
for(Account acc :Trigger.new()){
List<String> IDpvf = new List<String>();
IDpvf.add(acc.ID);
Map<ID,Visit__c> VisMap = new Map<ID,Visit__c>([Select Location__c,Primary_Visit_Focus__c from Visit__c where Location__c in :IDpvf ]);
for(Visit__c visit : VisMap.keyset())
{
if(acc.id == VisMap.get(visit.id).Location__c){
acc.PVF_value__c= VisMap.get(visit.id).Primary_Visit_Focus__c;
}
}
update IDpvf;
}
}
so you wont say anything will just post the code ? hmmmm ?
This should be working
Hi,
I think
is not updateable as this is list of string not a list of sobject.
And this trigger will fire after update then we cant able to update the accounts list if end user want this. Because in trigger we are updating the value of Account record .
Thanks.