function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc startsfdc start 

am confusing plz the code ....

write a trigger that wen account is created in '' FAX field   '' should be inserted while creating contact ........using afterinsert event.....
Best Answer chosen by sfdc start
SandhyaSandhya (Salesforce Developers) 
Hi,
It's working for me with below scenario.
Scenario to check

1.create new account with value in fax and save.

you see in the detail page contact will be created with same account name and fax.

User-added image


User-added image


Please make all other trigger inactive and only this trigger as active.

Hope this helps you!

Thanks and Regards
sandhya

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

From your question what I assume is whenever an account is created with fax field contact should be created with same fax field.

Below is the code for the same with all address field you can change according to your requirement.
trigger UpdateAcctPhone on Account (After insert) {
    if(trigger.isInsert)
    {
        List<contact> cc = new List<contact>();
        for(Account acc:Trigger.New)
        {
            Contact c = new Contact(LastName = acc.name, AccountId=acc.id,
	                        Fax=acc.Fax,
	                        MailingStreet=acc.BillingStreet,
	                        MailingCity=acc.BillingCity,
	                        MailingState=acc.BillingState,
	                        MailingPostalCode=acc.BillingPostalCode,
	                        MailingCountry=acc.BillingCountry,
	                        Phone=acc.Phone);
            cc.add(c);}
        System.debug('cccc'+cc);
           insert cc;
        
    }
    
}


Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
sfdc startsfdc start
its not working.........................check it onces
Vasani ParthVasani Parth
Try this,
 
trigger updateAccs on Account (after insert , after update){

if(trigger.isupdate && trigger.isafter){
    List<Contact> ct = new List <Contact>();
    Map<Id,Boolean> mapCheck = new Map<Id,Boolean>();
    for(Contact c : [SELECT LastName,AccountId FROM Contact WHERE AccountId IN : trigger.new]) {
        mapCheck.put(c.AccountId,true);
        if(c.LastName.contains('Billing Contact'))
            mapCheck.put(c.AccountId,false);
    }
    for(Account acc : trigger.new){
        if(mapCheck.get(acc.Id)) {
            Contact c = new Contact(LastName = acc.name + '-' +'Billing Contact',
                        AccountId=acc.id,
                        Fax=acc.Fax,
                        Phone=acc.Phone,
                        Contact_Type__c = true,
                        MailingStreet=acc.BillingStreet,
                        MailingCity=acc.BillingCity,
                        MailingState=acc.BillingState,
                        MailingPostalCode=acc.BillingPostalCode,
                        MailingCountry=acc.BillingCountry,
                        );
            ct.add(c);
        }
    }
    insert ct;
   }
}
Please mark this as the best answer if this helps
 
SandhyaSandhya (Salesforce Developers) 
Hi,
It's working for me with below scenario.
Scenario to check

1.create new account with value in fax and save.

you see in the detail page contact will be created with same account name and fax.

User-added image


User-added image


Please make all other trigger inactive and only this trigger as active.

Hope this helps you!

Thanks and Regards
sandhya
This was selected as the best answer