• Deepika Rahangdale
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
public class ContactRelatedController {
 public string accid ;
    public ContactRelatedController (){
        accid = apexpages.currentpage().getparameters().get('id');
        system.debug('Accid'+accid);
    }
    //Our collection of the class/wrapper objects cContact
    public List<cContact> contactList {get; set;}
    //This method uses a simple SOQL query to return a List of Contacts
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [select Id, Name, Email, Phone from Contact where AccountId=:accid]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }
    public PageReference processSelected() {
        //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<Contact> selectedContacts = new List<Contact>();
        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }
        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        for(Contact con : selectedContacts) {
            string conEmail = con.Email;
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            // Strings to hold the email addresses to which you are sending the email.
            String[] toAddresses = new String[] {conEmail};
                //String[] ccAddresses = new String[] {‘smith@gmail.com’};
                // Assign the addresses for the To and CC lists to the mail object.
                mail.setToAddresses(toAddresses);
            // mail.setCcAddresses(ccAddresses);
           
            mail.setSubject('New Mail Created using VF' );
            
           // mail.setPlainTextBody('Thank for U are created mail sussessful');
            mail.setHtmlBody('Thank for U are created mail sussessful      Thank for Contacting');
            // Send the email you have created.
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            // system.debug(con);
        }
        return null;
    }
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}
        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}
public class VFControllerPosition{
   //private final  Position__c pos1;
    private  ID recordId;
    public Position__c pos{set;get;}
private ApexPages.StandardController controller;
public VFControllerPosition(ApexPages.StandardController controller) {
this.pos = (Position__c)controller.getRecord();
    
}
    //Controller page 1
    public VFControllerPosition(){
    pos = new Position__c();
         recordId= ApexPages.currentPage().getParameters().get('id');
       
      pos = [Select id,Position_Title__c,Status__c,Name,Active__c from Position__c ];
        system.debug('vf6');
      
    }
        
   //*******Controller method for VF page 1************    
public PageReference Next() {
    insert pos;
PageReference VFpositionpage2 = Page.VFpositionpage2;
       VFpositionpage2.setRedirect(true);
        VFpositionpage2.getParameters();
            //.put('id',controller.getId());
        return page.VFpositionpage2; 
}
     //********Controller page 2********
  public PageReference save() {
        insert pos;
  PageReference VFpositionpage3= Page.VFpositionpage3;
         VFpositionpage3.setRedirect(true);
        VFpositionpage3.getParameters(); 
        return page.VFpositionpage3; 
    
}
     //*****************Controller page 3***********
     public PageReference redirect3(){
 PageReference VFpositionpage4= Page.VFpositionpage4;
         VFpositionpage4.setRedirect(true);
        VFpositionpage4.getParameters(); 
        return page.VFpositionpage4; 
         
         
    }
     public PageReference redirect4() {  
        
   //  if(controller.redirect4() != null) {
       PageReference pg  = new PageReference('/'+recordId);
        pg.setRedirect(true);
        return pg;


}
}
public class CreateTask  implements Database.Batchable<sObject>,  Schedulable{
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('SELECT ID,BillingState,BillingCountry,OwnerId FROM Account');
    }
    public void execute(Database.BatchableContext bc, List<Account> accountlist){
        List<Task> listtask= new List<Task>();
        for (Account acc : accountlist) {
            Task tobj = new Task();
             //tobj.Id=acc.OwnerId;
              tobj.Description='Created task';
            tobj.WhatId=acc.Id;
            tobj.IsReminderSet=true;
             listtask.add(tobj);
        }
            insert list task;
        }
    public void finish(Database.BatchableContext bc){
    }  
    public void execute(SchedulableContext ctx) {
          CreateTask CS1=new CreateTask();
        Database.executeBatch(CS1);
    }
}
test class of batch class to send an email to Opportunity owner. On 1st of each month send an email to Opportunity owner if close date is in this month.
public class VFControllerPosition{
   //private final  Position__c pos1;
    private  ID recordId;
    public Position__c pos{set;get;}
private ApexPages.StandardController controller;
public VFControllerPosition(ApexPages.StandardController controller) {
this.pos = (Position__c)controller.getRecord();
    
}
    //Controller page 1
    public VFControllerPosition(){
    pos = new Position__c();
         recordId= ApexPages.currentPage().getParameters().get('id');
       
      pos = [Select id,Position_Title__c,Status__c,Name,Active__c from Position__c ];
        system.debug('vf6');
      
    }
        
   //*******Controller method for VF page 1************    
public PageReference Next() {
    insert pos;
PageReference VFpositionpage2 = Page.VFpositionpage2;
       VFpositionpage2.setRedirect(true);
        VFpositionpage2.getParameters();
            //.put('id',controller.getId());
        return page.VFpositionpage2; 
}
     //********Controller page 2********
  public PageReference save() {
        insert pos;
  PageReference VFpositionpage3= Page.VFpositionpage3;
         VFpositionpage3.setRedirect(true);
        VFpositionpage3.getParameters(); 
        return page.VFpositionpage3; 
    
}
     //*****************Controller page 3***********
     public PageReference redirect3(){
 PageReference VFpositionpage4= Page.VFpositionpage4;
         VFpositionpage4.setRedirect(true);
        VFpositionpage4.getParameters(); 
        return page.VFpositionpage4; 
         
         
    }
     public PageReference redirect4() {  
        
   //  if(controller.redirect4() != null) {
       PageReference pg  = new PageReference('/'+recordId);
        pg.setRedirect(true);
        return pg;


}
}
1.created custom button on details page of account account "show" requirement is:
when click on this button show rcontacts  related to account in table format.
  • May 27, 2021
  • Like
  • 0
test class of batch class to send an email to Opportunity owner. On 1st of each month send an email to Opportunity owner if close date is in this month.
In the Navigation and Customization section, I am a bit confused
(Personalize your view of account pages
Customize your account detail page layout. Make the Open Activities related list the first one you see on account record detail pages. Then create an account called Goat Wranglers R Us and check the account page to make sure Open Activities appears first.
Make Open Activities the first related list on the record detail page for accounts
Create an account with Account Name: Goat Wranglers R Us)


Could somebody walk me through this process?

Hey community,

I'm struggling with the logic of the task...

To complete this challenge, add a validation rule which will block the insertion of a contact if the contact is related to an account and has a mailing postal code (which has the API Name MailingPostalCode) different from the account's shipping postal code (which has the API Name ShippingPostalCode).Name the validation rule 'Contact must be in Account ZIP Code'.

A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode should return with a validation error and not be inserted.

The validation rule should ONLY apply to contact records with an associated account. Contact records with no associated parent account can be added with any MailingPostalCode value. (Hint: you can use the ISBLANK function for this check)

Here is what I got so far:

AND(
 NOT(ISBLANK(MailingPostalCode)),
 MailingPostalCode  <>  Account.ShippingPostalCode )

I THINK I know how to see if the contact mailing zip is not the same as the account shipping zip, and only if the is not blank.

The part I am stuck on is if the "Contact records with no associated parent account can be added with any MaiilingPostalCode value"...

I don't know what to do with that.

Also, I am now getting the error message when I recheck challenge:

Challenge not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact_must_be_in_Account_ZIP_Code: [] 


Double help, please.