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
raj sfdc 8raj sfdc 8 

when ever account type is changed form any value to 'Customer' need to send an email to account owner saying your account become customer and create a task and assign it to account owner.

when ever account type is changed form any value to 'Customer' need to 
send an email to account owner saying your account become customer 
and create a task and assign it to account owner.
sowmya Inturi 9sowmya Inturi 9
Hi Raj,
You can create a workflow with your criteria and create a email alert and task for your workflow rule.

Let me know if you need any help in creating the work flow.

Thank you,
Sowmya.
suresh beniwal 21suresh beniwal 21
Just write the below code in the update trigger for account object


 public static void sendemailAndCreateTask(List<Account> accountlist, Map<Id, Account> oldAccountMap) { 
        Map<Id, Account> mapofAccountWithOwner = new Map<Id, Account>([Select id, owner.Email, ownerid from account where id in:oldAccountMap.keySet() ]);
        for (Account a: accountlist){
            if(a.Type == 'Customer - Direct' && a.Type != oldAccountMap.get(a.Id).Type) {
                Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
                String[] sendingTo = new String[]{mapofAccountWithOwner.get(a.Id).Owner.Email};
                    semail.setToAddresses(sendingTo);
                semail.setSubject('Single Email message Example');
                semail.setPlainTextBody('your account become customer ');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
                
                Task task = new Task();
                task.ActivityDate = System.today();
                task.ownerId = mapofAccountWithOwner.get(a.Id).Owner.ID;
                task.Subject = 'Other';
                task.priority= 'High';
                task.status = 'Not Started';
                task.description = 'New  Work';
                insert task;
            }
        }
    }


Please let me know if you face any further issue
TruptiTrupti
Hi Raj,

You can accomplish above requirement using workflow rule.
1.Set Evaluation Criteria: Evaluate the rule when a record is created, and every time it's edited.
2.Rule Criteria: ISCHANGED( AccountType) && ISPICKVAL(AccountType, 'Customer')
3.Add Immidiate workflow actions: Email Alert and New Task.

Hope this helps!
Mark as best answer if it solves your requirement.
Thanks
suresh beniwal 21suresh beniwal 21
Hi Trupti,

As per requirement Task should have the account owner as task owner, but with workflow we cannot assign the owner dynamically.
So to achieve this we need to write the apex logic, In my above comment used the APEX logic to fulfill the requirement.

Hoping this helps, Mark as best answer if this resolves your query.
Thanks,
Suresh Beniwal 
TruptiTrupti
Hi Suresh,

We can assign Owner dynamically.

User-added image

Assign To is 'Owner' of Task.