You need to sign in to do that
Don't have an account?

Hii Please help me
Hii Friends,
I want code for upsert records
I have oject Timesheet__c custom object.
Which has following filed.
Name
Month__c(Master_detail with Month__c object)
Resource__c(Lookup with Resource__c object)
i want code for if the Timesheet for that Month is already exist then update that records if not then create new record.
this is my code
Above not updating existing records.It creating new records.
Please help me as soon as possible. Its very urgent
Thanks in advance
I want code for upsert records
I have oject Timesheet__c custom object.
Which has following filed.
Name
Month__c(Master_detail with Month__c object)
Resource__c(Lookup with Resource__c object)
i want code for if the Timesheet for that Month is already exist then update that records if not then create new record.
this is my code
Timesheet__c ts=new Timesheet__c(); ts.Month__c=new_records3.Id; ts.Resource__c=currentRecord.Resource__c; List<Timesheet__c> tlist=new List<Timesheet__c>(); tlist=[SELECT ID,Name,Month__r.Name,Resource__r.Name FROM Timesheet__c WHERE Month__r.Name=: new_records3.Name AND Resource__r.Name=:currentRecord.Resource__r.Name]; if(tlist.size()>0){ for(Timesheet__c t:tlist){ update ts t.ID; } } else insert ts;
Above not updating existing records.It creating new records.
Please help me as soon as possible. Its very urgent
Thanks in advance
Please use below peace of code and check the result. Hopefully by this change your issue is resolved.
and please give response.
If it work fine then please select as the best answer.
Thanks,
Annu Choudhary
All Answers
Can you please explain what is currentRecord here and how you get this. Can you show me that soql from which you get currentRecord .
There are Month__c and Monthaly_salary__c is two different object right ???
No both are same
On Timesheet__c object Month__c is name of Master -detail relationship with Monthly_Salary__c object.
Please use below peace of code and check the result. Hopefully by this change your issue is resolved.
and please give response.
If it work fine then please select as the best answer.
Thanks,
Annu Choudhary
It works. :)
Regards,
Akshata