+ Start a Discussion
HelloSanHelloSan 

i have account and year fields on opportunity object when i insert new child Service(Custom Object)to opportunity object i need to cross check whether there are any childs for that account and year before inserting new child,i need apex code for this

child object name is concatenation of account and year.
HelloSanHelloSan
for(opportunity opp:trigger.new)
{
//Here I need to get opp year and account where these fields are common for Opportunity and Service
list<Service__c> slist=[SELECT  id,name from Service Where year == opp.year and accountid == opp.accountid ];
}
if(slist.size() ==0)
{
insert service;
}
else
{
update service;
}