You need to sign in to do that
Don't have an account?
Rakheeb
scenario:how can i send email to perticuler user when the user record is created on contact?
HI guys , whenever user is created it will generete email i.e username and new password to a perticular user.same thing i am doing on Contact when the record is created then i want to generate email to perticular contact person i.e username and new password.So how can i do that kindly let me know solution.
Do you want to send email to User's Email and Contact Email both .
If you don't want to send email to userEmail
then do this before you insert user record.
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.EmailHeader.triggerUserEmail = false;
insert user;
after insertion send mail to contact email using apex code.
To get password you have to update password using
System.ResetPasswordResult result = System.resetPassword(portalUserId,false);
result.getPassword() will give you password
Send this in a mail using apex code. like this
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Set target Object id to your contactid
mail.setTargetObjectId(contactID);
//Set body , subject and other things
//Send mail
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I hope this will help you.
But i want to send only Contact email i.e when the record is created on contact then email will generate automatically to a perticuler contact i.e username and new password.so let me know the solution with code.
This will stop the mail to user's email
dmo.EmailHeader.triggerUserEmail = false;
Database.DMLOptions dmo = new Database.DMLOptions();
Please see it in my solution.
But i dont want email body and subject ,when we are creating any user that will Generate new password and notify user immediately to a perticular user.but same thing i want when the new record is created on contact it will Generate new password and notify user immediately for perticular contact based on the email.So kindly let me know the solution
I got your issue that you don't want mail to go to user email but to go to contact email. There is no such option in salesforce directly which sends email to contact email, partenr seeting only allow you to change from address and to addredss is always user email.
Thats why I suggested you to stop then default mail and then send you mail to contact email.
You can try one more thing but very little chance it will work
Change email of user to contact email and create user and Update user email to its original one after that.
Hi Shashikant Sharma , can you provide me a apex code alone with this.Advance thanks
I can give you in peices
dmo.EmailHeader.triggerUserEmail = false;
User u = new User();
//above code will stop mail to user email
Database.DMLOptions dmo = new Database.DMLOptions();
//fil all the fieds before insert1
insert user
//Now send your email through code with user name password
//You can get user name from user object instance
//Get new password
System.ResetPasswordResult result = System.resetPassword(portalUserId,false);
//Send Mail
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//targer object sould be your contact id
//set contact id in mail.setTargetObjectId
Messaging.SingleEmailMessage[] { mail });
Folow above approach definitly solve your issue, please let me know if any issues come while you implement this approach
//See this for email send : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm
how can i get the current detail page id from Contact i.e when the record is saved .But i know using visual force page we can create like this "select Email from Contact where id = :ApexPages.currentPage().getParameters().get('id')];" but how can i get the id from conatct detail page(because i want to send email to perticular contact ). so kindly let me know using above query string
While creating user you must have a contactid in it , so you can get contact id from your user object.