• Aishwarya P 4
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 5
    Replies
I have a visual force page, which has two fields.
Field 1 : Order status (Type : picklist) : it has 4 values 
New
WIP
Closed
Cancelled

Field 2 : Cancellation reason (type : picklist) : it has two values
Issue Solved
Not required

So when i select cancelled option from field 1, then field 2 should become editable else it should be read only.
and if cancelled is selected in field 1 then you cannot save without the cancellation reason.

Please help me write the vf page and vf controller class.
I have a visual force page, which has two fields.
Field 1 : Order status (Type : picklist) : it has 4 values 
New
WIP
Closed
Cancelled

Field 2 : Cancellation reason (type : picklist) : it has two values
Issue Solved
Not required

So when i select cancelled option from field 1, then field 2 should become editable else it should be read only.
and if cancelled is selected in field 1 then you cannot save without the cancellation reason.

Please help me write the vf page and vf controller class.


 
This is the class :

public class emailid
{
    
    public string emailidnoti{get;set;}
             
    public emailid() 
    {
    }
    public emailid(ApexPages.StandardController controller)
    {
    }   
    public void sendnotification()
    {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.toAddresses = new String[] { ???????}
        message.subject = 'Email Notification From XYZ Page';
        message.plainTextBody = 'Hello !! Your Business Details were successfully displayed';
        Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
    }
}

This is the visualforce code :

<apex:page sidebar="false" showHeader="False" standardStylesheets="false">
     <style>
        .myFormStyle
        {
            background-color : #FEF9E7;
             margin: auto;
            width: 50%;
            border: 3px solid green;
            padding: 10px;            
        }
        
    </style>
       <apex:form styleClass="myFormStyle">
       <center><h1>Welcome To The Page </h1></center>
       <center><h3><b><u><i> {! $user.FirstName} </i></u></b></h3></center> <br/>
       <apex:pageBlock>
       <p4><font size="2" color="Red"><font color="Black">NAME : </font> {! $user.FirstName}</font></p4><br/>
       <p4><font size="2" color="Red"><font color="Black">EMAIL-ID :</font> {! $user.Email} </font></p4><br/>
       </apex:pageBlock> 
       <apex:pageBlock title="Email">
       <apex:commandButton action="{!sendnotification}" value="Send Notification"/>
       </apex:pageBlock>
       </apex:form>

</apex:page>

How to send the email to the user ?
How to access the user's email id in the To address?
<apex:page sidebar="false" showHeader="False" standardStylesheets="false">
     <style>
        .myFormStyle
        {
            background-color : #FEF9E7;
             margin: auto;
            width: 50%;
            border: 3px solid green;
            padding: 10px;            
        }
        
    </style>
       <apex:form styleClass="myFormStyle">
       <center><h1>Welcome To The Page </h1></center>
       <center><h3><b><u><i> {! $user.FirstName} </i></u></b></h3></center> <br/>
       <apex:pageBlock>
       <p4><font size="2" color="Red"><font color="Black">NAME : </font> {! $user.FirstName}</font></p4><br/>
       <p4><font size="2" color="Red"><font color="Black">EMAIL-ID :</font> {! $user.Email} </font></p4><br/>
       </apex:pageBlock> 
       <apex:pageBlock title="Email">
       <apex:inputText label ="Email-Id for Notification"/>
       </apex:pageBlock>
       </apex:form>

</apex:page>

I want to send an email to the email Id which he will enter in the input text field.
Please help
<apex:page sidebar="false" showHeader="False">
    <apex:image id="theImage" value="C:\Users\Desktop\Notepad\SE.png" width="220" height="55": />  
</apex:page>

This is my code.Please help
This is the controller class:

public class MYAPEX_Acc
{
    public static void createcon(List<Account> lstaccforcon)
    {
        List<Contact> lstcon = new List<Contact>();
        for(Account acc : lstaccforcon)
        {
        Contact newcon = new Contact();
        newcon.AccountId = acc.Id;
        newcon.FirstName = acc.Name;
        newcon.Description = acc.Description;
        newcon.Phone = acc.Phone;
        newcon.Email = acc.Email__c;
        lstcon.add(newcon);        
        }
        try{
        INSERT lstcon;
        }
        catch(exception e)
        {
        }
    }
}


This is the trigger :

trigger AishuAccount on Account (before insert,before update,after insert,after update) 
{
    List<Account> lstacc = new List<Account>();
    List<Account> lstaccforcon = new List<Account>();
    List<Contact> lstcon = new List<Contact>();

    If(Trigger.isAfter)
        {
        If(Trigger.isInsert)
        {
      
        for(Account acc : Trigger.new)
        {
        If(acc.Phone != NULL && acc.Name != NULL)
        lstaccforcon.add(acc);
        }
        }
       
        If(lstaccforcon.size() > 0)
        {
        MYAPEX_Acc.createcon(lstaccforcon);
        }
    }
    
}


I'm unable to create a contact with this code. please help
public class OlderAccountsUtility
{
    public static void updateOlderAccounts()
    {
        List<Account> lstacc = [SELECT ID,Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
        
        for(Account acc : lstacc)
        {
            acc.Description = 'Heritage Account';
        }
        
        try
        {
        update lstacc;
        }
        catch(exception e)
        {
        }
    }
}


when i execute this code it is giving an error:
"Challenge Not yet complete... here's what's wrong: 
The 'updateOlderAccounts' method did not update account records as expected "

PLease help me with this
When an Opportunity is deleted, a mail should be generated to inform the Owner of the Account informing him about this.
//Trigger:
trigger EmailOnDelete on Opportunity (after delete) {
    Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Opportunity opp : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'ash@gmail.com'});
        email.setSubject('Trigger on Oppurtunity Activated : Deleted Account Alert');
        email.setPlainTextBody('This message is to alert you that the account named ' + opp.Name + ' has been deleted.');
        emails.add(email);
    }
    Messaging.sendEmail(emails);
}


I'm able to write the trigger, But i want a class method to be called in trigger and all the actions to happen in the class method. 
This is the class :

public class emailid
{
    
    public string emailidnoti{get;set;}
             
    public emailid() 
    {
    }
    public emailid(ApexPages.StandardController controller)
    {
    }   
    public void sendnotification()
    {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.toAddresses = new String[] { ???????}
        message.subject = 'Email Notification From XYZ Page';
        message.plainTextBody = 'Hello !! Your Business Details were successfully displayed';
        Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
    }
}

This is the visualforce code :

<apex:page sidebar="false" showHeader="False" standardStylesheets="false">
     <style>
        .myFormStyle
        {
            background-color : #FEF9E7;
             margin: auto;
            width: 50%;
            border: 3px solid green;
            padding: 10px;            
        }
        
    </style>
       <apex:form styleClass="myFormStyle">
       <center><h1>Welcome To The Page </h1></center>
       <center><h3><b><u><i> {! $user.FirstName} </i></u></b></h3></center> <br/>
       <apex:pageBlock>
       <p4><font size="2" color="Red"><font color="Black">NAME : </font> {! $user.FirstName}</font></p4><br/>
       <p4><font size="2" color="Red"><font color="Black">EMAIL-ID :</font> {! $user.Email} </font></p4><br/>
       </apex:pageBlock> 
       <apex:pageBlock title="Email">
       <apex:commandButton action="{!sendnotification}" value="Send Notification"/>
       </apex:pageBlock>
       </apex:form>

</apex:page>

How to send the email to the user ?
How to access the user's email id in the To address?
This is the controller class:

public class MYAPEX_Acc
{
    public static void createcon(List<Account> lstaccforcon)
    {
        List<Contact> lstcon = new List<Contact>();
        for(Account acc : lstaccforcon)
        {
        Contact newcon = new Contact();
        newcon.AccountId = acc.Id;
        newcon.FirstName = acc.Name;
        newcon.Description = acc.Description;
        newcon.Phone = acc.Phone;
        newcon.Email = acc.Email__c;
        lstcon.add(newcon);        
        }
        try{
        INSERT lstcon;
        }
        catch(exception e)
        {
        }
    }
}


This is the trigger :

trigger AishuAccount on Account (before insert,before update,after insert,after update) 
{
    List<Account> lstacc = new List<Account>();
    List<Account> lstaccforcon = new List<Account>();
    List<Contact> lstcon = new List<Contact>();

    If(Trigger.isAfter)
        {
        If(Trigger.isInsert)
        {
      
        for(Account acc : Trigger.new)
        {
        If(acc.Phone != NULL && acc.Name != NULL)
        lstaccforcon.add(acc);
        }
        }
       
        If(lstaccforcon.size() > 0)
        {
        MYAPEX_Acc.createcon(lstaccforcon);
        }
    }
    
}


I'm unable to create a contact with this code. please help
I am trying to pass Quick start Apex Step two. I have copy and pasted the code given

public class OlderAcccountsUtility {
public static void updateOlderAccounts() {
// Get the 5 oldest accounts
Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
// loop through them and update the Description field
for (Account acct : oldAccounts) {
acct.Description = 'Heritage Account';
}
// save the change you made
update oldAccounts;


but I am getting the below error message

Step Not yet complete... here's what's wrong: 
The 'updateOlderAccounts' method did not update account records as expected 
Note: you may run into errors if you've skipped previous steps.

Can Someone please look over what I am doing wrong?