You need to sign in to do that
Don't have an account?
KR_Force
Can some one please help me with this code??
Need to auto populate productionsubscription__c(multi piclist on contact). all i have to do is based on Contact.AccountID i need to pull the Linked accounts and
1.Filter those linked accounts by agent_c == true && cases__c == true && expiration__c > today (or expiration_c empty)
2. Get the agents of the of the linked accounts filtered in the previous step (i.e. a list of all linkedAccount.agent_Contact__c).
3. Get the linked accounts of the agents gotten in the previous step. and
select LINKED_ACCOUNT_FIELDS
from Linked_account__c
where isDeleted = false
and Agent__c = false
and Agent_Contact__c in (STEP_2_AGENTS)
Step 4: for all these linked account.AccountS and Contact.AccountID need to query the asset with product familiy field and get the uniq value and populate contact productSubscription__c field.
I'mcalling this method from before insert trigger.
*****ANY HELP WILL BE MUCH APPRICITED*******
1.Filter those linked accounts by agent_c == true && cases__c == true && expiration__c > today (or expiration_c empty)
2. Get the agents of the of the linked accounts filtered in the previous step (i.e. a list of all linkedAccount.agent_Contact__c).
3. Get the linked accounts of the agents gotten in the previous step. and
select LINKED_ACCOUNT_FIELDS
from Linked_account__c
where isDeleted = false
and Agent__c = false
and Agent_Contact__c in (STEP_2_AGENTS)
Step 4: for all these linked account.AccountS and Contact.AccountID need to query the asset with product familiy field and get the uniq value and populate contact productSubscription__c field.
I'mcalling this method from before insert trigger.
*****ANY HELP WILL BE MUCH APPRICITED*******
- public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
- //set<id>acIds=new set<Id>();
- set<id>acIds1=new set<Id>();
- list<Asset>ast=new List<Asset>();
- List<Linked_Account__c>lActs=new List<Linked_Account__c>();
- List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
- Map<Id,Linked_Account__c>actLActMap=new Map<Id,Linked_Account__c>();
- Map<Id,ID>alActs=new Map<Id,ID>();
- Map<Id,Id>conActMap=new Map<Id,Id>();
- Map<ID,String>ActPfamilyMap=new Map<ID,String>();
- set<id>aContacts=new set<id>();//Agent Contacts
- for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
- if(acids.size()>0){
- lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=true and Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
- }
- if(lActs.size()>0){
- for(Linked_Account__c l:lActs){
- aContacts.add(l.Agent_Contact__c);
- actLActMap.put(l.Linked_Account__c,l);
- }
- }
- if(aContacts.size()>0){
- linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=false and isDeleted=false and Agent_Contact__c in:aContacts];
- }
- if(linkedAccounts.size()>0){
- For(Linked_Account__c l1:linkedAccounts){
- acIds1.add(l1.Account__c);
- //aContact.put(l1.Agent_Contact__c,l1.Account__c);
- }
- }
- acIds1.addAll(acIds);
- String psubscription;
- if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
- for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);}
- for(contact c :newcontacts){
- list<Linked_Account__c>l1=actLActMap.get(c.AccountId);
- set<id>acts=add(c.accountid);
- for(Linked_Account__c l:l1){acts.add(alActs.get(l.Agent_Contact__c));
- List<Asset>ast=ActPfamilyMap.get(acts);
- }
- for(Asset a1:ast){
- psubscription+=a1.Product_Family__c+'; ';}
- c.productSubscriptions__c=psubscription;
- }
- }
All Answers
Are u getting any errors if yes post the error below.
thanks,
pradeep
I'm a total newbie to Apex and have diligently searched and searched through out the forums for a solution to my problem..
Check ur trigger is in active mode or not checked ur code its ok i didn't find error.
thanks,
pradeep.
Error: Invalid Data.
Review all error messages below to correct your data.
An Error occured at trigger XXXXXXXXX on contact:System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)