You need to sign in to do that
Don't have an account?
vinay kumar 1170
i have a custom object appointments__c it has a field called status__c .when status__c is changed from confirmed to visited then account record should be created.these two objects has a master detail relationship where account is parent
trigger capture on Appointment__c (after update)
{
list<account> acclist = new list<account> ();
for(Appointment__c app: trigger.new)
{
if(app.Status__c=='Confirmed' && trigger.oldMap.get(app.Id).Status__c=='Visited')
{
account acc = new account();
acc.Patient_Name__c = app.Id;
acc.Phone_Number__c = app.Contact_Number__c;
acc.Email__c = app.Email__c;
acclist.add(acc);
}
}
if(acclist.size()>0)
{
try{
insert acclist;
}
catch(System.DmlException e)
{
System.debug(e);
}
}
}
{
list<account> acclist = new list<account> ();
for(Appointment__c app: trigger.new)
{
if(app.Status__c=='Confirmed' && trigger.oldMap.get(app.Id).Status__c=='Visited')
{
account acc = new account();
acc.Patient_Name__c = app.Id;
acc.Phone_Number__c = app.Contact_Number__c;
acc.Email__c = app.Email__c;
acclist.add(acc);
}
}
if(acclist.size()>0)
{
try{
insert acclist;
}
catch(System.DmlException e)
{
System.debug(e);
}
}
}
trigger capture on Appointment__c (after update)
{
list<account> acclist = new list<account> ();
for(Appointment__c app: trigger.new)
{
if(app.Status__c=='Visited' && trigger.oldMap.get(app.Id).Status__c=='Confirmed')
{
account acc = new account();
acc.Name='Test Account';
acc.Patient_Name__c = app.Id;
acc.Phone_Number__c = app.Contact_Number__c;
acc.Email__c = app.Email__c;
acclist.add(acc);
}
}
if(acclist.size()>0)
{
try{
insert acclist;
}
catch(System.DmlException e)
{
System.debug(e);
}
}
}
All Answers
I guess you are having trouble associating the account record with the custom object record.
Please confirm
If you are using standard Account Object then Account Name is the mandatory field to insert new Account.
Account acc = new Account();
acc.Name ='Test';
Let me know if any problem occurs again.
Please mark it as best answer if you find it helpful.
Thank You
Ajay Dubedi
trigger capture on Appointment__c (after update)
{
list<account> acclist = new list<account> ();
for(Appointment__c app: trigger.new)
{
if(app.Status__c=='Visited' && trigger.oldMap.get(app.Id).Status__c=='Confirmed')
{
account acc = new account();
acc.Name='Test Account';
acc.Patient_Name__c = app.Id;
acc.Phone_Number__c = app.Contact_Number__c;
acc.Email__c = app.Email__c;
acclist.add(acc);
}
}
if(acclist.size()>0)
{
try{
insert acclist;
}
catch(System.DmlException e)
{
System.debug(e);
}
}
}