You need to sign in to do that
Don't have an account?
rohi rohi
select after for loop
Hi,
I'm new to salesforce.
In trigger handler i need to check values based on contact id.
First i need to check the contact id in contacts object then take that contact id and check whether that id is exists in Request custom object along with other fields.If the second query returns empty then i need to add that contact id in Request object.
following is my code
public static void createProces(List<Contact> oContacts)
{
List<Request__c> lsProcess_Request;
Request__c oRequest = new Request__c();
List<Request__c> uRequest = new List<Request__c>();
for (Contact c : [SELECT Id, Email,Status__c FROM Contact WHERE Id IN: oContacts] )
{
//check whether active process or not
lsProcess_Request =[SELECT Active__c ,Member__c,attempt_1__C,attempt_2__C,Attempt_1__c,Attempt___c FROM Request__c WHERE
member__c =: c.Id and Active__c=true and (Attempt_1__c = true OR Attempt_2 __c = true )];
if(lsProcess_Request == null)
{
oRequest.Member__c = c.id;
oRequest.Attempt_1_Date__c = Date.today();
oRequest.Attempt_2_Date__c = Date.today()+3;
lwr.add(oRequest);
}
}
}
Please advise me on this.
I'm new to salesforce.
In trigger handler i need to check values based on contact id.
First i need to check the contact id in contacts object then take that contact id and check whether that id is exists in Request custom object along with other fields.If the second query returns empty then i need to add that contact id in Request object.
following is my code
public static void createProces(List<Contact> oContacts)
{
List<Request__c> lsProcess_Request;
Request__c oRequest = new Request__c();
List<Request__c> uRequest = new List<Request__c>();
for (Contact c : [SELECT Id, Email,Status__c FROM Contact WHERE Id IN: oContacts] )
{
//check whether active process or not
lsProcess_Request =[SELECT Active__c ,Member__c,attempt_1__C,attempt_2__C,Attempt_1__c,Attempt___c FROM Request__c WHERE
member__c =: c.Id and Active__c=true and (Attempt_1__c = true OR Attempt_2 __c = true )];
if(lsProcess_Request == null)
{
oRequest.Member__c = c.id;
oRequest.Attempt_1_Date__c = Date.today();
oRequest.Attempt_2_Date__c = Date.today()+3;
lwr.add(oRequest);
}
}
}
Please advise me on this.
Hey,
You are doing SOQL query in a for loop. Do not do this. Ever. Since you are a beginner, make it a practice to recheck your code whenever you are using loops and queries in your class.
Since the records oContacts are coming from the trigger, I omitted your first query and for loop. There might be another simple way to do this, but this is what came from the top of my mind. Try this out, and let me know if I misunderstood the problem.
Thanks,
Sidhant