• Cloud-Ling
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies

Greetings,

 

Now I have to create a trigger on Account that would parse the information(Name__c, Phone__c, Email__c, Address__c) in an XML format. I have to parse the information upon creating new record on Account and save the data to its appropriate fields on Contact object.

 

i.e. XML file --

 

<?xml version="1.0" ?> 
<!--My first XML document --> 
   <information> 
        <name>
	  <first_name>Seed</first_name>
	  <last_name>Lins</last_name>
	</name>
        <phone>888-8888-88</phone> 
        <email>email@email.com</email>
        <address>Texas,USA</address> 
   
        <name>
	  <first_name>R</first_name>
	  <last_name>Coholick</last_name>
	</name>
        <phone>662-546-54546</phone> 
        <email>email@email.com</email>
        <address>Denver,USA</address> 
  </information>

 

 

 

What am I gonna do?? I'm really confuse. Please help. Any ideas are welcome.

 

 

Thanks,

C-L

Greetings,

 

Any idea why i can't send Email? my code below

 

Class Code:

 

public class EmailMessage
{  
   public static void SendEmail()
   {
       System.debug('Sending Email...');
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] toAdd = new String[]{'m*******','l*******com','t******.com'};
       mail.setToAddresses(toAdd);
       mail.setReplyTo('ke****.com');
       mail.setSenderDisplayName('Salesforce Notification');
       mail.setSubject('Duplicating Account Name');
       mail.setBccSender(false);
       mail.setUseSignature(false);
       mail.setPlainTextBody('Some user attempts to duplicate you Account Name.');
       List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[] { mail });
       System.debug('Email Sent: '+results.get(0).isSuccess() );
    }
}

 Trigger Code:

 

trigger ErrorDuplicateOutput on Account (before insert, before update)
{
  List<Account> accList =new List<Account>();
  Set<String> b = new Set<String>();
  accList = [Select Name FROM Account];
  
  for (Account acc : accList)
  {
   b.add(acc.Name);
  }
  
  for(integer x = 0; x < Trigger.new.size(); x++)
  {
      if(b.contains(Trigger.new[x].name))
      {
          Trigger.new[x].addError('Error:Account name already exist!');
          EmailMessage.SendEmail();
      }
  }
}

 

Any ideas are welcome, thank you!

S-L

 

 

on making Apex Classes,

 

  • Should @isTest always be private class?
Thanks,
C-L

 

Heya,

My code has no error on compilation but when it came to addError, it didn't work when I gave it a try.. here's my code, tell me what's jiffy in it.

 

trigger ErrorDuplicateOutput on Account (before insert, before update)
{
  List<Account> accList =new List<Account>();
  Set<String> b = new Set<String>{'Express Logistics and Transport','Edge Communications'};
  accList = [Select Id, Name FROM Account Where Name in: b];
  
  for (Account acc : accList)
  {
   if (b.contains(acc.Name))
   {
    acc.Name.addError('Account name already exist!');
   }
  }
  update accList;
}

 Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ErrorDuplicateOutput caused an unexpected exception, contact your administrator: ErrorDuplicateOutput: execution of BeforeInsert caused by: System.FinalException: SObject row does not allow errors: Trigger.ErrorDuplicateOutput: line 11, column 5

 

Greetings,

 

Now I have to create a trigger on Account that would parse the information(Name__c, Phone__c, Email__c, Address__c) in an XML format. I have to parse the information upon creating new record on Account and save the data to its appropriate fields on Contact object.

 

i.e. XML file --

 

<?xml version="1.0" ?> 
<!--My first XML document --> 
   <information> 
        <name>
	  <first_name>Seed</first_name>
	  <last_name>Lins</last_name>
	</name>
        <phone>888-8888-88</phone> 
        <email>email@email.com</email>
        <address>Texas,USA</address> 
   
        <name>
	  <first_name>R</first_name>
	  <last_name>Coholick</last_name>
	</name>
        <phone>662-546-54546</phone> 
        <email>email@email.com</email>
        <address>Denver,USA</address> 
  </information>

 

 

 

What am I gonna do?? I'm really confuse. Please help. Any ideas are welcome.

 

 

Thanks,

C-L

on making Apex Classes,

 

  • Should @isTest always be private class?
Thanks,
C-L

 

Heya,

My code has no error on compilation but when it came to addError, it didn't work when I gave it a try.. here's my code, tell me what's jiffy in it.

 

trigger ErrorDuplicateOutput on Account (before insert, before update)
{
  List<Account> accList =new List<Account>();
  Set<String> b = new Set<String>{'Express Logistics and Transport','Edge Communications'};
  accList = [Select Id, Name FROM Account Where Name in: b];
  
  for (Account acc : accList)
  {
   if (b.contains(acc.Name))
   {
    acc.Name.addError('Account name already exist!');
   }
  }
  update accList;
}

 Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ErrorDuplicateOutput caused an unexpected exception, contact your administrator: ErrorDuplicateOutput: execution of BeforeInsert caused by: System.FinalException: SObject row does not allow errors: Trigger.ErrorDuplicateOutput: line 11, column 5

 

Am I losing my mind? The snippet below isn't updating my contacts, I don't get any errors or anything it just dosn't update the records. The number of DML rows: 197 out of 10000 is reported and expected. There are no triggers in the org that would get in the way.

 

 

Account a = [select id, name from account where name='New Name'];
List<Contact> cList = [Select id, name, account.name from contact where account.name = 'Old Name'];
for(contact i : cList) {
    i.account = a;
}
update cList;

 

 

  • November 12, 2010
  • Like
  • 0