i want to create a record if it doesn’t exist
$qBean = BeanFactory::getBean('E14_LOB');
$beanList = $qBean->retrieve_by_string_fields(
array(
'name' => $app_list_strings['lob_list'][$list[$i]],
'opportunityid_c'=>$bean->opportunityid_c,
)
);
if($qBean->id==null){
bean created
i am using this code but still causing duplicate records
so what am i doing wrong
rsp
13 December 2024 15:11
2
Check out this code:
$qBean = BeanFactory::getBean('E14_LOB');
$searchCriteria = array(
'name' => $app_list_strings['lob_list'][$list[$i]],
'opportunityid_c' => $bean->opportunityid_c
);
$qBean = $qBean->retrieve_by_string_fields($searchCriteria);
if (empty($qBean->id)) {
$qBean = BeanFactory::newBean('E14_LOB');
$qBean->name = $app_list_strings['lob_list'][$list[$i]];
$qBean->opportunityid_c = $bean->opportunityid_c;
$qBean->save();
}
pgr
13 December 2024 15:30
3
@hserour you should be looking at the returned $beanList, not at $qBean.
can you please tell me how
this is also creating duplicates
pgr
13 December 2024 15:51
6
If you’re not spending even a minute to think about this and try solutions yourself, how can you ask me to spend several minutes explaining things to you? I have my own work to accomplish, sorry.
rsp
13 December 2024 16:15
8
Check out this code:
$qBean = BeanFactory::getBean('E14_LOB');
$searchCriteria = array(
'name' => $app_list_strings['lob_list'][$list[$i]],
'opportunityid_c' => $bean->opportunityid_c
);
$beanList = $qBean->get_by_string_fields($searchCriteria);
if (empty($beanList)) {
$qBean = BeanFactory::newBean('E14_LOB');
$qBean->name = $app_list_strings['lob_list'][$list[$i]];
$qBean->opportunityid_c = $bean->opportunityid_c;
$qBean->save();
} else {
$qBean = $beanList[0];
}