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

there are four objects accounts , policy(custom object) , opportunity , application(custom object). account and policy have masterdetail relationship , account and opportunity also have MD relation. and opportunity have lookup relation with application .
there are four objects accounts , policy(custom object) , opportunity , application(custom object). account and policy have masterdetail relationship , account and opportunity also have MD relation. and opportunity have lookup relation with application . every application must have one opportunity assigned.
there is one field on application called 'status'.
requiremet :when application status is 'approved by CMS' . check if related account with opportunity have assigned active policy?if yes , update application status to "Enrolled" .
code i have written
trigger UpdateApplicationStatusToEnrolled on vlocity_ins__Application__c (before update) {
Map <string,List<vlocity_ins__Application__c>> strMap = new Map <string,List<vlocity_ins__Application__c>>();
set<id> oppid = new set<id>();
for(vlocity_ins__Application__c app :trigger.new)
{
if(app.vlocity_ins__Status__c=='Approved by CMS')
{
oppid.add(app.id);}}
List<opportunity> oppDetails=[SELECT id, AccountId, Account.name ,Account.vlocity_ins__ActivePolicyNumber__c
FROM Opportunity where Account.vlocity_ins__ActivePolicyNumber__c >=1 and id IN: oppid];
for(vlocity_ins__Application__c app : Trigger.new)
{
List<vlocity_ins__Application__c> appList = strMap.containsKey(app.opportunityid) ? strMap.get(app.opportunityId) : new List<vlocity_ins__Application__c>();
appList.add(app);
strMap.put(app.opportunityId, appList);
}
}
getting error , please help
there is one field on application called 'status'.
requiremet :when application status is 'approved by CMS' . check if related account with opportunity have assigned active policy?if yes , update application status to "Enrolled" .
code i have written
trigger UpdateApplicationStatusToEnrolled on vlocity_ins__Application__c (before update) {
Map <string,List<vlocity_ins__Application__c>> strMap = new Map <string,List<vlocity_ins__Application__c>>();
set<id> oppid = new set<id>();
for(vlocity_ins__Application__c app :trigger.new)
{
if(app.vlocity_ins__Status__c=='Approved by CMS')
{
oppid.add(app.id);}}
List<opportunity> oppDetails=[SELECT id, AccountId, Account.name ,Account.vlocity_ins__ActivePolicyNumber__c
FROM Opportunity where Account.vlocity_ins__ActivePolicyNumber__c >=1 and id IN: oppid];
for(vlocity_ins__Application__c app : Trigger.new)
{
List<vlocity_ins__Application__c> appList = strMap.containsKey(app.opportunityid) ? strMap.get(app.opportunityId) : new List<vlocity_ins__Application__c>();
appList.add(app);
strMap.put(app.opportunityId, appList);
}
}
getting error , please help
Error: Compile Error: Variable does not exist: oppDetails at line 20 column 69 . and please let me know if i am doing it correctly or not . its urgent please help.
Thanks
The only thing that I might guess is the issue is you could change the key of the map from string to Id as that is what you are really dealing with. to
Map <string,List<vlocity_ins__Application__c>> strMap = new Map <string,List<vlocity_ins__Application__c>>();
set<id> oppid = new set<id>();
for(vlocity_ins__Application__c app :trigger.new)
{
if(app.vlocity_ins__Status__c=='Approved by CMS')
{
oppid.add(app.id);}}
List<opportunity> oppDetails=[SELECT id, AccountId, Account.name ,Account.vlocity_ins__ActivePolicyNumber__c
FROM Opportunity where Account.vlocity_ins__ActivePolicyNumber__c >=1 and id IN: oppid];
for(vlocity_ins__Application__c appl : Trigger.new)
{
List<vlocity_ins__Application__c> appList = strMap.containKey(appl.oppDetails.id) ? strMap.get(appl.oppDetails.id) : new List<vlocity_ins__Application__c>();
appList.add(appl);
strMap.put(appl.oppDetails.id, appList);
}
}
Error: Error Error: Compile Error: Variable does not exist: oppDetails at line 20 column 69
Error: Compile Error: A non foreign key field cannot be referenced in a path expression: Opportunity__c at line 20 column 69
List<vlocity_ins__Application__c> appList = strMap.containKey(appl.oppDetails[i].id) ? strMap.get(appl.oppDetails[i].id) : new List<vlocity_ins__Application__c>();
i will be the integer for iterating based on the size of the oppDetails.
Error: Compile Error: Variable does not exist: oppDetails at line 20 column 68
for(Opportunity opp : oppDetails)
or
for(Interger i ; i <= oppDetails.size(); i++)
I do not see you doing that at all. Unless that is done you may not find the desired result you are expecting.
trigger UpdateApplicationStatusToEnrolled on vlocity_ins__Application__c (before update) {
Map <string,List<vlocity_ins__Application__c>> strMap = new Map <string,List<vlocity_ins__Application__c>>();
set<id> oppid = new set<id>();
for(vlocity_ins__Application__c app :trigger.new)
{
if(app.vlocity_ins__Status__c=='Approved by CMS')
{
oppid.add(app.id);}}
List<opportunity> oppDetails=[SELECT id, AccountId, Account.name ,Account.vlocity_ins__ActivePolicyNumber__c
FROM Opportunity where Account.vlocity_ins__ActivePolicyNumber__c >=1 and id IN: oppid];
for(Opportunity opp : oppDetails)
{
List<vlocity_ins__Application__c> appList = strMap.containKey(opp.oppDetails[i].id) ? strMap.get(opp.oppDetails[i].id) : new List<vlocity_ins__Application__c>();
appList.add(opp);
strMap.put(opp.OppDetails[i].id, appList);
}
}
getting below error: Error Error: Compile Error: Variable does not exist: oppDetails at line 20 column 67
List<vlocity_ins__Application__c> appList = strMap.containKey(opp.id) ? strMap.get(opp.id) : new List<vlocity_ins__Application__c>();
It should work as expected since you are iterating through Opportunity.