• Madevala Jithender
  • NEWBIE
  • 40 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 0
    Replies
Create an Apex class that returns accounts
Create an Apex class that returns a List of Account objects for a user-specified state.
Create an Apex class that contains a static method:
Name: AccountUtils
Method name: accountsByState
The method must return the ID and name of all Account objects that match the BillingState for the state abbreviation passed to the method
Below is my code
public class AccountUtils {
    public static list<account>  accountsByState(string st){
        List<account> acctlist = [select id,name from account where BillingState =:st];
        return acctlist;
    }

}
Challenge not yet complete in My Trailhead Playground 1
Executing the 'accountsByState' method on 'AccountUtils' failed. Make sure that you named your method correctly, that it's public and static, and that it accepts a String and returns a List of Account objects.
public class PropertyUtility {
    public static void newListedProperties(){
        List<Property__c> newproplist = new list<Property__c>();
        newproplist = [select id,name,Broker__r.Email__c,Days_on_market__c from Property__c where Days_on_market__c<=30];
        
        for(Property__c P:newproplist){
            string propEmail = p.name + ':' + p.Broker__r.Email__c;
            system.debug(propEmail);
        }
    }

}
public class ContactandLeadSearch {
    public static list<list<sobject>> searchcontactsandleads(string lastname){
        
        list<list<sobject>> contactleadlist = [find : lastname in all fields returning contact (name),Lead(name)];
        return contactLeadlist;
    }

}
trigger ClosedOpportunityTriigger on Opportunity (after insert,after update) {
    list<task> tasklist = new list<Task>();
    
    for(opportunity opp : Trigger.new){
        if(opp.stagename == 'closed won'){
            tasklist.add(new task(subject = 'follow up Test Task',whatid = opp.id));
        }
    }if(tasklist.size()>0){
        insert tasklist;
    }

}
public class AccountUtility {
    public static void ViewAnnualRevenue(){
        list<account> accountlist = [select id,name,annualrevenue from account];
        for(account acc : accountlist){
            string acctrev = acc.name + ':' + acc.annualrevenue;
            system.debug('acctrev'+acctrev);
        }
    }

}
public class AccountHandler {
    public static Account insertNewAccount(string name){
        Account a = new Account();
        a.name = name;
        
        try{
            insert a;
        }catch(exception e){
            return null;
        }
        return a;
    }

}
trigger AccountAddressTrigger on Account (before insert,before update) {
    
    for(Account account:Trigger.new){
        if(account.Match_Billing_Address__c==True){
            account.shippingpostalcode=account.Billingpostalcode;
        }
    }

}
public class ContactSearch {
    public static list<contact> searchforcontacts(string lastname,string mailingpostalcode){
        list<contact> contacts = 
            [select id,name,lastname,mailingpostalcode from contact where lastname = :lastname and mailingpostalcode = :mailingpostalcode];
        system.debug('found contacts:' + contacts);
        return contacts;
    }

}