• Rvsk
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I have created a Custom field called “Number of Locations” on the Account Object (Data Type=Number)
Object : Account
Trigger: After Insert

This is my code:

trigger ContactsCreation on Account (after insert) {
list<contact> listContact = new list<contact>();
map<id,decimal> mapAcc = new map<id,decimal>();
  for(Account acc:trigger.new){
      mapAcc.put(acc.id,acc.NumberofLocations__c);
     }
        if(mapAcc.size()>0 && mapAcc!=null){
            for(Id accId:mapAcc.keyset()){
               for(integer i=0;i<mapAcc.get(accId);i++){
                 contact newContact=new contact();
                 newContact.accountid=accId;
                 newContact.lastname='contact'+i;
                 listContact.add(newContact);
                 }
              }
         }
if(listContact.size()>0 && listContact!=null)
insert listContact;

Can someone please explain the logic behind the no of creation of contact records based on location field.
Sample example: I have given account name,no of locations=2 in account object, then after two contacts record got created with lastname as contact0,contact1.
Why multiple contacts are creating as per the above logic?
 
  • March 25, 2021
  • Like
  • 0
I am new to Salesforce environment. Can someone please help me with the below.

I have Created a field on Account called “Only_Default_Contact”, checkbox= default off

When a new Account is created, we should create a new Contact that has the following data points:

First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.
  • March 17, 2021
  • Like
  • 0
I am new to Salesforce environment. Can someone please help me with the below.

I have created a field on Contact called Profile, text, 255.
When an Account is updated and the Website is filled in, update all the Profile field on all Contacts to:
Profile = Website + ‘/’ + First Letter of First Name + Last Name

I got this error, "Method does not exist or incorrect signature: void get(integer) from the type string" for the below code:

public class createAccandContact {
public static void createContactRec(list<Account> acc)
{
    list<Contact> clist = new list<contact>();
    for(account a:acc)
    {
    Contact c= new contact();
   c.Profile__c = a.website + '/' + c.firstname.get(0) + c.LastName;
    clist.add(c);
    }   
     update clist; 
   }
}

Respective Trigger for the above:
trigger createAccRecord on Account (after update) 
{
createAccandContact.createContactRec(Trigger.new);
}
  • March 17, 2021
  • Like
  • 0
I have created a Custom field called “Number of Locations” on the Account Object (Data Type=Number)
Object : Account
Trigger: After Insert

This is my code:

trigger ContactsCreation on Account (after insert) {
list<contact> listContact = new list<contact>();
map<id,decimal> mapAcc = new map<id,decimal>();
  for(Account acc:trigger.new){
      mapAcc.put(acc.id,acc.NumberofLocations__c);
     }
        if(mapAcc.size()>0 && mapAcc!=null){
            for(Id accId:mapAcc.keyset()){
               for(integer i=0;i<mapAcc.get(accId);i++){
                 contact newContact=new contact();
                 newContact.accountid=accId;
                 newContact.lastname='contact'+i;
                 listContact.add(newContact);
                 }
              }
         }
if(listContact.size()>0 && listContact!=null)
insert listContact;

Can someone please explain the logic behind the no of creation of contact records based on location field.
Sample example: I have given account name,no of locations=2 in account object, then after two contacts record got created with lastname as contact0,contact1.
Why multiple contacts are creating as per the above logic?
 
  • March 25, 2021
  • Like
  • 0
I am new to Salesforce environment. Can someone please help me with the below.

I have Created a field on Account called “Only_Default_Contact”, checkbox= default off

When a new Account is created, we should create a new Contact that has the following data points:

First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.
  • March 17, 2021
  • Like
  • 0