• NewBee21
  • NEWBIE
  • 50 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 9
    Replies
I have written a Trigger in which whenever I create an Account, new Contacts are created with the Last Name same as the Account Name. But now when I try to update the Account Name, Contact's last name remains unchanged. I want it to get updated whenever I update my Account Name. How do I achieve this?

**Trigger** ==>

trigger Account1 on Account (after insert,after update) {
    list <contact> con=new list <contact>();    
    for(Account acc : trigger.new){
        contact c = new contact();
        c.LastName = acc.Name;
        c.AccountID = acc.ID;
        con.add(c);    
    }
    insert con;
}
Trigger on Contact Object where object having custom currency field 'salary'. The requirement is with event after insert, after update and after delete, minimum and maximum salary of contact should get updated.

Kindly help,I will appreciate it a lot!
Hello,I have written an apex class and now testing the class to achieve 100% code coverage.I have followed the steps as per trailhead but now getting the following error.

@isTest
public Class AccountRelatedCase{
@isTest    
    public Static void list<Case> lstCases(string Accid){
    
    list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
    system.Debug(lstCa);
    return lstCa;
    }
}

Error:
Unexpected token 'list'.
public class CaseAccount {
public static void (){
Account accts=[SELECT Id, name FROM Account WHERE Id NOT IN ( SELECT AccountId FROM Case WHERE IsClosed = true ) ] ; } }

Error I am getting :
1.static is not allowed on constructors
2.Invalid constructor name: method

What could be the reason and how do I navigate to solution. Previously I used static in other example and at that time I did not get any erros.

requirement: "Write a class to get the list of all open cases related to an account. Class should have one method with account id as an input parameter and return list of cases
Error on VF page after preview:

The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

I think it has to do with edit/delete command action link which I added.So kindly review and let me know where to make changes.

**controller**

public with sharing class DisplayAccWithContact3 {

    public PageReference DeleteContact() {
        return null;
    }

    public Contact con{get;set;}
    public DisplayAccWithContact3() {
        con=new contact();
    }
    public List<Contact> contacts {get; set;}
    public string SelectedContactId { get; set; }
    
    public PageReference showContacts() {
        contacts = [SELECT Name, Phone, Email FROM Contact WHERE AccountId = :con.accountid];
        return null;        
    }
     
           public void DeleteAccount()
           
           {
// if for any reason we are missing the reference
if (SelectedContactId== null) {

return;
}

// find the account record within the collection
Contact tobeDeleted = null;
for(Contact a : Contacts)
if (a.Id == SelectedContactId) {
tobeDeleted = a;
break;
}

//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}
}
}

**VF Page**

<apex:page sidebar="false" controller="DisplayAccWithContact3">
    <apex:form > 
    <style type="text/css">
    .bPageBlock .pbTitle {
     width: 100%;    
     text-align: center; }
     </style>
<apex:pageBlock title= "Account Information"/>
    <apex:outputText value="Enter Account Name:"></apex:outputText>    
        <apex:inputfield value="{!con.accountid}"/>
        <apex:commandButton value="ShowContacts" action="{!showContacts}" rerender="out" status="mystatus"/><br/>
        
        <apex:actionstatus id="mystatus" starttext="please wait contacts are loading.......">
            <apex:facet name="stop">
                <apex:outputpanel id="out">
                    <apex:pageBlock >
                        <apex:pageBlockSection >
                            <apex:pageBlockTable value="{!Contacts}" var="c" rendered="{!con.accountid !=null}">
                            <apex:column >
<apex:outputLink title="" value="/{!c.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!c.Id}');" style="font-weight:bold">Del</a>
</apex:column>
                                <apex:column headerValue="Name">
                                    {!c.Name}
                                </apex:column>
                                <apex:column headerValue="Phone">
                                    {!c.Phone}
                                </apex:column>
                                <apex:column headerValue="Email">
                                    {!c.Email}
                                </apex:column>
                            </apex:pageBlockTable>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:outputpanel>
            </apex:facet>
        </apex:actionstatus>
        <apex:actionFunction action="{!DeleteContact}" name="DeleteContact" reRender="form" >
<apex:param name="contactid" value="" assignTo="{!SelectedContactId}"/>
</apex:actionFunction>
    </apex:form>
</apex:page>
My requirement is I want the contacts of the Account which I search with the look up (see screenshot) and then I will get contacts related to the account to me.

heres what i achieved till the lookup part,but now stuck with how do i get contacts fetched to me of the account.

**controller**

public class freshcontroller1
{
public contact con {get;set;}
Account ac;

  public freshcontroller1(ApexPages.Standardcontroller controller)
 {
 con =new contact();
 }
public Account getAc()
{
return ac;
}
 
  public pagereference showcontact()
  {
  ac = [select id from Account where id=:con.accountid];
  System.debug('Ac  '+ac);
  return null;
  }  
  public pagereference Contact()
  {
  con=[select id,Name,Phone from Contact where id=:con.accountid];
  System.debug('contacts are '+con);
  return null;
  }
  
}


*VF Page**

<apex:page standardController="Account" extensions="freshcontroller1">
<apex:form > <apex:pageBlock title="Account information"/>
<apex:inputField value="{!con.accountid}"/>
<apex:commandButton action="{!showcontact}" value="Display contacts"/>
<apex:pageBlock > <apex:pageBlockTable value="{!con}" var="c"/>
</apex:pageBlock>
</apex:form>
</apex:page>
I am getting this error while previewing visualforce page. ==> Error: Unknown property 'AccountStandardController.con'


Visualforce page:

<apex:page standardController="Account" extensions="ExtensionController5">
<apex:form >
<apex:pageBlock title="Account Information" id="account"> <apex:pageBlocksection>
<apex:inputField value="{!con.accountId}"/>
<apex:actionsupport event="onchange" action="{!accountselected}" rerender="account,msgs" status="stat"/>
</apex:pageBlockSection
</apex:pageBlock>
</apex:form>
</apex:page>


Controller:

public class ExtensionController5{ private ApexPages.StandardController Stdctrl;
public ExtensionController5(ApexPages.StandardController controller){ Stdctrl=controller; }
public void AccountSelected() { contact con=(contact) StdCtrl.getRecord();
if (!string.IsBlank(con.accountid))
{ con.account=[select Name,Phone from Account where id=:con.accountid]; }
else { con.account=null; } } }
I have written a Trigger in which whenever I create an Account, new Contacts are created with the Last Name same as the Account Name. But now when I try to update the Account Name, Contact's last name remains unchanged. I want it to get updated whenever I update my Account Name. How do I achieve this?

**Trigger** ==>

trigger Account1 on Account (after insert,after update) {
    list <contact> con=new list <contact>();    
    for(Account acc : trigger.new){
        contact c = new contact();
        c.LastName = acc.Name;
        c.AccountID = acc.ID;
        con.add(c);    
    }
    insert con;
}
Trigger on Contact Object where object having custom currency field 'salary'. The requirement is with event after insert, after update and after delete, minimum and maximum salary of contact should get updated.

Kindly help,I will appreciate it a lot!
Hello,I have written an apex class and now testing the class to achieve 100% code coverage.I have followed the steps as per trailhead but now getting the following error.

@isTest
public Class AccountRelatedCase{
@isTest    
    public Static void list<Case> lstCases(string Accid){
    
    list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
    system.Debug(lstCa);
    return lstCa;
    }
}

Error:
Unexpected token 'list'.
public class CaseAccount {
public static void (){
Account accts=[SELECT Id, name FROM Account WHERE Id NOT IN ( SELECT AccountId FROM Case WHERE IsClosed = true ) ] ; } }

Error I am getting :
1.static is not allowed on constructors
2.Invalid constructor name: method

What could be the reason and how do I navigate to solution. Previously I used static in other example and at that time I did not get any erros.

requirement: "Write a class to get the list of all open cases related to an account. Class should have one method with account id as an input parameter and return list of cases
My requirement is I want the contacts of the Account which I search with the look up (see screenshot) and then I will get contacts related to the account to me.

heres what i achieved till the lookup part,but now stuck with how do i get contacts fetched to me of the account.

**controller**

public class freshcontroller1
{
public contact con {get;set;}
Account ac;

  public freshcontroller1(ApexPages.Standardcontroller controller)
 {
 con =new contact();
 }
public Account getAc()
{
return ac;
}
 
  public pagereference showcontact()
  {
  ac = [select id from Account where id=:con.accountid];
  System.debug('Ac  '+ac);
  return null;
  }  
  public pagereference Contact()
  {
  con=[select id,Name,Phone from Contact where id=:con.accountid];
  System.debug('contacts are '+con);
  return null;
  }
  
}


*VF Page**

<apex:page standardController="Account" extensions="freshcontroller1">
<apex:form > <apex:pageBlock title="Account information"/>
<apex:inputField value="{!con.accountid}"/>
<apex:commandButton action="{!showcontact}" value="Display contacts"/>
<apex:pageBlock > <apex:pageBlockTable value="{!con}" var="c"/>
</apex:pageBlock>
</apex:form>
</apex:page>
I am getting this error while previewing visualforce page. ==> Error: Unknown property 'AccountStandardController.con'


Visualforce page:

<apex:page standardController="Account" extensions="ExtensionController5">
<apex:form >
<apex:pageBlock title="Account Information" id="account"> <apex:pageBlocksection>
<apex:inputField value="{!con.accountId}"/>
<apex:actionsupport event="onchange" action="{!accountselected}" rerender="account,msgs" status="stat"/>
</apex:pageBlockSection
</apex:pageBlock>
</apex:form>
</apex:page>


Controller:

public class ExtensionController5{ private ApexPages.StandardController Stdctrl;
public ExtensionController5(ApexPages.StandardController controller){ Stdctrl=controller; }
public void AccountSelected() { contact con=(contact) StdCtrl.getRecord();
if (!string.IsBlank(con.accountid))
{ con.account=[select Name,Phone from Account where id=:con.accountid]; }
else { con.account=null; } } }