You need to sign in to do that
Don't have an account?
mallikharjunarao gunda
can we update the records without having any relationships
hail see my code it cannot updated
trigger Activestatus on Policy_Holder__c (after insert) {
list<Motor_Insurance__c>motor=new list<Motor_Insurance__c>();
set<id>setid=new set<id>();
if(trigger.isafter && trigger.isinsert){
for(Policy_Holder__c p:trigger.new)
{
if(p.status__c==true)
{
setid.add(p.Id);
}
}
}
list<Motor_Insurance__c> mot=[select id,Premium_Amount__c,No_of_Terms__c,status__c
from Motor_Insurance__c where id=:setid];
if(mot.size()>0 && mot.size()!=null){
for(Motor_Insurance__c c:mot)
{
if(c.status__c==false){
c.status__c=true;
}
}
}
update mot;
}
trigger Activestatus on Policy_Holder__c (after insert) {
list<Motor_Insurance__c>motor=new list<Motor_Insurance__c>();
set<id>setid=new set<id>();
if(trigger.isafter && trigger.isinsert){
for(Policy_Holder__c p:trigger.new)
{
if(p.status__c==true)
{
setid.add(p.Id);
}
}
}
list<Motor_Insurance__c> mot=[select id,Premium_Amount__c,No_of_Terms__c,status__c
from Motor_Insurance__c where id=:setid];
if(mot.size()>0 && mot.size()!=null){
for(Motor_Insurance__c c:mot)
{
if(c.status__c==false){
c.status__c=true;
}
}
}
update mot;
}
can we update the record
In "setid', you are storing the ID's of 'Policy_Holder__c' records and while querying 'Motor_Insurance__c 'records into mot, you are checking id's in setid which definitely results in 'Null' in mot.
Please let us know if there is no relationship between those objects, when Policy_Holder__c is inserted, which Motor_Insurance__c record should be updated in the trigger ?
Best Regards,
BALAJI