You need to sign in to do that
Don't have an account?
Packaging Person Accounts
Hi,
I have a problem with Person account fields.. I know we cannot associate person account fields with package.. So I wrote a general trigger regarding my project and I wrote another trigger for person accounts. My plan is to give the trigger to the users who wants to use person accounts along with my application..
But., I have faced one problem. In my general trigger i'm calling the xml field from data__c object. Through that xml tags I'm updating different objects., while inserting xml data into account object., I wrote another code for person accounts.
General trigger:
for(CnPData__c cpdata:Trigger.new){
dataxml=cpdata.DataXML__c;
cpordnum = cpdata.OrderNumber__c;
}
XmlStreamReader reader= new XmlStreamReader(dataxml);
Contact con= parseContact(reader);
contacts.add(con);
Account a = new Account();
a.Name = firstname+' '+lastname;
a.BillingStreet = add2;
a.BillingCity = city;
a.BillingState= state;
a.BillingCountry = country;
a.BillingPostalCode= postalcode;
a.ShippingStreet = shipadd2;
a.ShippingCity = shipcity;
acc.add(a);
if(!acc.isEmpty()&&( xmlvalue[0].Accounts__c == true ||xmlvalue[0].Person_Accounts__c == true) ){
insert acc;
}
Contact parseContact(XmlStreamReader reader1){
Contact contact = new Contact();
while(reader1.hasNext()) {
if ('Patron' == reader.getLocalName() && reader.getEventType() == XmlTag.END_ELEMENT) {
break;
}
else if('BillingFirstName' == reader.getLocalName() && reader.getEventType() == XmlTag.START_ELEMENT){
reader.next();
if(reader.getEventType() == XmlTag.CHARACTERS) {
contact.FirstName = reader.getText();
firstname = contact.FirstName;
}
}
else if('BillingLastName' == reader.getLocalName()&& reader.getEventType() == XmlTag.START_ELEMENT){
reader.next();
if(reader.getEventType() == XmlTag.CHARACTERS) {
contact.LastName = reader.getText();
lastname = contact.LastName;
}
}
}
My Account Trigger:
for(Account a :Trigger.new){
if(xmlvalue[0].Person_Accounts__c == true && !rt.isEmpty()){
a.firstname = firstname;
a.lastname = lastname;
a.RecordTypeId =rt[0].Id;
a.PersonEmail =email;
}
}
If I give static values for firstname and lastname it is working.. But, how to give the values dynamically.,coming from the xml..
First general trigger works on CnPData__c before insert... second one works on Account after insert.
Thanks in Advance..
Anu