+ Start a Discussion
sudheer raju 10sudheer raju 10 

Sends the email to the owner when I open the record

Hi to all,
          I am new to salesforce I have one scenario,when I open the record automatically it sends the email to the owner.How can we achieve this scenario.Please help.

Tanks in advance
Pankaj_GanwaniPankaj_Ganwani
Hi Sudheer,

Override the View link of the record. You can refer below mentioned code:
 
<apex:page standardController = "Account" extensions="ext" action="{!redirect}">
</apex:page>
 
public class ext
{
    private Id recId;
    public ext(apexpages.standardcontroller std)
    {
            recId = std.getId();
    }

    public pagereference redirect()
    {
             //send email coding will come here.
             
            return new pagereference('/'+recId );
    }
}

 
Veenesh VikramVeenesh Vikram
Hi Sudheer,

For implementing this, you may write a Simple VF page, in the Page's constructor/Action, you send out an email to the Owner.
You then embed this VF page as an "Inline VF Page" in the Record's detail page.

So now, every time record is opened, the VF page will Load, the constructor  called and mail sent:)

Hope this helps!

Veenesh
RatanRatan
Pankaj idea is correct one except one thing once you sent the email you need to redirect to detail page again

You just to append nooverride=1 in url 

like this
 
public class ext
{
    private Id recId;
    public ext(apexpages.standardcontroller std)
    {
            recId = std.getId();
    }

    public pagereference redirect()
    {
             //send email coding will come here.
             
            return new pagereference('/'+recId+'?nooverride=1' );
    }
}



 
sudheer raju 10sudheer raju 10
thanks pankaj,vineesh and ratan.
Pankaj_GanwaniPankaj_Ganwani
Hey Sudheer,

Please close this thread by making it as solved.

Thanks,
Pankaj