• farah sherif
  • NEWBIE
  • 225 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 40
    Questions
  • 41
    Replies
WHEN i RUN THIS PART OF THE CODE IT GIVES ME THE BELOW ERROR ALTHOUGH IT USED TO WORK BEFORE

 if(a[0].Product_Family__c == '360 Suite'){
            a[0].Status = 'Canceled';
        }
        




error:

System.ListException: List index out of bounds: 0
i have this error
System.NullPointerException: Attempt to de-reference a null object
       
with this line in the code but it used to work before 
acc.RecordTypeId=Schema.SObjectType.Account.getRecordTypeInfosByName().get('Parent').getRecordTypeId();
 
Create an Apex class called 'DailyLeadProcessor' that uses the Schedulable interface.
The execute method must find the first 200 Leads with a blank LeadSource field and update them with the LeadSource value of 'Dreamforce'.
Create an Apex test class called 'DailyLeadProcessorTest'.
In the test class, insert 200 Lead records, schedule the DailyLeadProcessor class to run and test that all Lead records were updated correctly.
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.

Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.

The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.

Create an Apex test class called 'AddPrimaryContactTest'.

In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
need help on how to create thi process 

You've been given a requirement to keep contact addresses in sync with the accounts they belong to. Use Process Builder to create a process on the Account object that updates child Contact addresses when an account's address is updated.

Challenge Requirements:
The process can have any name
The process must have an Update Records action that updates Contact mailing address fields (Street, City, State, Postal Code, Country) when the parent Account shipping address field values are updated
The process must be active
need help with this trialhead modile

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 saved
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)


I wrote this but it's incorrect
 MailingPostalCode !=  Account.ShippingPostalCode 
anyone know how to fix this code for the custom template region to be centered and wide using lightning component


<aura:component implements="lightning:homeTemplate" 
                description="Lightning Home Page Template with One Region" >
    <aura:attribute name="column1" type="Aura.Component[]" />
    
    
    <div>
        <lightning:layout horizontalAlign="spread" pullToBoundary="small">
            <lightning:layoutItem size="4" flexibility="grow" 
                                  padding="around-small">
                {!v.column1}
            </lightning:layoutItem>
           
        </lightning:layout>
    </div> 
</aura:component>
<aura:component implements="lightning:homeTemplate" 
                description="Lightning Home Page Template with One Region" >
    <aura:attribute name="column1" type="Aura.Component[]" />
    
    
    <div>
        <lightning:layout horizontalAlign="spread" pullToBoundary="small">
            <lightning:layoutItem size="4" flexibility="grow" 
                                  padding="around-small">
                {!v.column1}
            </lightning:layoutItem>
           
        </lightning:layout>
    </div> 
</aura:component>
anyone have an idea on how to create a custom template on lightning app builder
how do I create a custom template in lightning app builder where the page is not divided it's only one part
I wrote this code to solve the trialhead but it gives me this error on trialhead 


error:   The page does not include an &lt;apex:image&gt; component

code:
<apex:page showHeader="false">
    <img id="theImage" src="https://developer.salesforce.com/files/salesforce-developer-network-logo.png" />
</apex:page>

trialhead challenge:
Create a Visualforce page without the standard Salesforce header and display an image using the Visualforce image component. 
Challenge Requirements
The page must be named DisplayImage
It must NOT display the standard Salesforce header
It must use a Visualforce apex:image component to display this image - https://developer.salesforce.com/files/salesforce-developer-network-logo.png
 
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.
Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.
The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.
Create an Apex test class called 'AddPrimaryContactTest'.
In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".

public class UpdateParentAccount implements Queueable {
private List<Account> accounts;
private ID parent;
public UpdateParentAccount(List<Account> records, ID id) {
this.accounts = records; this.parent = id;
}
public void execute(QueueableContext context) {
for (Account account : accounts)
{
account.parentId = parent;
// perform other processing or callout
}
update accounts;
}
}
 Create an Apex class called 'LeadProcessor' that uses the Database.Batchable interface.
Use a QueryLocator in the start method to collect all Lead records in the org.
The execute method must update all Lead records in the org with the LeadSource value of 'Dreamforce'.
Create an Apex test class called 'LeadProcessorTest'.
In the test class, insert 200 Lead records, execute the 'LeadProcessor' Batch class and test that all Lead records were updated correctly.
The unit tests must cover all lines of code included in the LeadProcessor class, resulting in 100% code coverage.
Create a field on the Account object called 'Number_of_Contacts__c' of type Number. This field will hold the total number of Contacts for the Account.
Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.
For each Account ID passed to the method, count the number of Contact records associated to it and update the 'Number_of_Contacts__c' field with this value.
Create an Apex test class called 'AccountProcessorTest'.
this is the requirment:
When Cancellation_Received_Date__c is populated on an AssetRecord,

Copy Actual_Cancellation_Date__c from the Asset Object

To Actual_Cancellation_Date__c on the OpportunityLineItem Object

Use Opportunity_Product_ID__c on the Asset Object to determine which Opportunityline item to update


trigger CopyDateTrigger on Asset (after update, after delete) {

    map<id,date> toupdate = new map<id,date>();
    map<id,id> toupdate2 = new map<id,id>();
    map<Asset,id> toupdate3 = new map<Asset,id>();
    //set<id> opp = new set<id>();
    for(Asset a:trigger.new){
        
        if(a.Cancellation_Received_Date__c  != null){
            toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);

            toupdate2.put(a.Opportunity__c,a.Opportunity_Product_ID__c);
            toupdate3.put(a,a.Opportunity_Product_ID__c);
        }
    }
    if(!toupdate.isEmpty() ){
        List<OpportunityLineItem> o = [select Casesafeid__c,Actual_Cancellation_Date__c from OpportunityLineItem where Casesafeid__c in:toupdate.keySet()];
    
        
        for(OpportunityLineItem opp:o){
            for(Asset ast:toupdate3.keySet()){
             
                if(ast.Opportunity_Product_ID__c == opp.Casesafeid__c){
                    opp.Actual_Cancellation_Date__c  =ast.Actual_Cancellation_Date__c;
                }
            }
    }
    }
}

 
this is supposed to be the function of the trigger:
When Cancellation_Received_Date__c is populated on an AssetRecord,

Copy Actual_Cancellation_Date__c from the Asset Object

To Actual_Cancellation_Date__c on the OpportunityLineItem Object

Use Opportunity_Product_ID__c on the Asset Object to determine which Opportunityline item to update

I wrote the below trigger but I can't write the part where is copies the actual cancellation




trigger CopyDateTrigger on Asset (after update, after delete) {

    map<id,date> toupdate = new map<id,date>();
    
    for(Asset a:trigger.new){
        
        if(a.Actual_Cancellation_Date__c != null){
            toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);

        }
    }
    if(!toupdate.isEmpty() ){
        for(Id i:toupdate.keySet()){
        
        }
    }
}
public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
//check for date2 being in the past
if( date2 < date1) { return false; }
//check that date2 is within (>=) 30 days of date1
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 >= date30Days ) { return false; }
else { return true; }
}
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}
i have this error
System.NullPointerException: Attempt to de-reference a null object
       
with this line in the code but it used to work before 
acc.RecordTypeId=Schema.SObjectType.Account.getRecordTypeInfosByName().get('Parent').getRecordTypeId();
 
the trigger should be on account to check the assets and if ALL Assets where product family = "bla bla "  and their status was "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c )  to "Cancel".
i have this error
System.NullPointerException: Attempt to de-reference a null object
       
with this line in the code but it used to work before 
acc.RecordTypeId=Schema.SObjectType.Account.getRecordTypeInfosByName().get('Parent').getRecordTypeId();
 
Create an Apex class called 'DailyLeadProcessor' that uses the Schedulable interface.
The execute method must find the first 200 Leads with a blank LeadSource field and update them with the LeadSource value of 'Dreamforce'.
Create an Apex test class called 'DailyLeadProcessorTest'.
In the test class, insert 200 Lead records, schedule the DailyLeadProcessor class to run and test that all Lead records were updated correctly.
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.

Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.

The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.

Create an Apex test class called 'AddPrimaryContactTest'.

In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
<aura:component implements="lightning:homeTemplate" 
                description="Lightning Home Page Template with One Region" >
    <aura:attribute name="column1" type="Aura.Component[]" />
    
    
    <div>
        <lightning:layout horizontalAlign="spread" pullToBoundary="small">
            <lightning:layoutItem size="4" flexibility="grow" 
                                  padding="around-small">
                {!v.column1}
            </lightning:layoutItem>
           
        </lightning:layout>
    </div> 
</aura:component>
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.
Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.
The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.
Create an Apex test class called 'AddPrimaryContactTest'.
In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
Create a field on the Account object called 'Number_of_Contacts__c' of type Number. This field will hold the total number of Contacts for the Account.
Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.
For each Account ID passed to the method, count the number of Contact records associated to it and update the 'Number_of_Contacts__c' field with this value.
Create an Apex test class called 'AccountProcessorTest'.
this is the requirment:
When Cancellation_Received_Date__c is populated on an AssetRecord,

Copy Actual_Cancellation_Date__c from the Asset Object

To Actual_Cancellation_Date__c on the OpportunityLineItem Object

Use Opportunity_Product_ID__c on the Asset Object to determine which Opportunityline item to update


trigger CopyDateTrigger on Asset (after update, after delete) {

    map<id,date> toupdate = new map<id,date>();
    map<id,id> toupdate2 = new map<id,id>();
    map<Asset,id> toupdate3 = new map<Asset,id>();
    //set<id> opp = new set<id>();
    for(Asset a:trigger.new){
        
        if(a.Cancellation_Received_Date__c  != null){
            toupdate.put(a.Opportunity_Product_ID__c,a.Actual_Cancellation_Date__c);

            toupdate2.put(a.Opportunity__c,a.Opportunity_Product_ID__c);
            toupdate3.put(a,a.Opportunity_Product_ID__c);
        }
    }
    if(!toupdate.isEmpty() ){
        List<OpportunityLineItem> o = [select Casesafeid__c,Actual_Cancellation_Date__c from OpportunityLineItem where Casesafeid__c in:toupdate.keySet()];
    
        
        for(OpportunityLineItem opp:o){
            for(Asset ast:toupdate3.keySet()){
             
                if(ast.Opportunity_Product_ID__c == opp.Casesafeid__c){
                    opp.Actual_Cancellation_Date__c  =ast.Actual_Cancellation_Date__c;
                }
            }
    }
    }
}

 
public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
//check for date2 being in the past
if( date2 < date1) { return false; }
//check that date2 is within (>=) 30 days of date1
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 >= date30Days ) { return false; }
else { return true; }
}
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}
@isTest
public class AssetTriggerTest2 {

    @isTest static void test(){
        
        Account acc = new Account();
        acc.Name = 'farah test';
        insert acc;
        
        Opportunity opp = new Opportunity();
        opp.Name = 'tests';
        opp.CloseDate = Date.today();
        opp.StageName ='Demo';
        opp.AccountId = acc.Id;
        opp.Type='New';
        opp.Demo_Date__c = Date.today();
        opp.New_Vehicle_Feed_Provider__c ='AutoFunds';
        insert opp;
        
        Product2 p1 = new Product2();
        p1.Family = '360 Suite';
        p1.IsActive = true;
        p1.Name ='360 Suite';    
        insert p1;
        
        Id pricebookId = Test.getStandardPricebookId();
        PricebookEntry pb1 = new PricebookEntry();
        pb1.Product2Id =p1.Id;
        pb1.Pricebook2Id = pricebookId;
        pb1.UnitPrice = 100.00;
        pb1.IsActive = true;
        insert pb1;
        
        
        OpportunityLineItem oli = new OpportunityLineItem(
                                                 OpportunityId = opp.Id,
                                                 Quantity = 5,
                                                 PricebookEntryId = pb1.Id,
                                                 TotalPrice = Quantity * pb1.UnitPrice
                                                                                    );
        insert oli;
        

        opp.StageName = 'Closed Won';
        update opp;
        
       
        
    }
    
}




error
Variable does not exist: Quantity


although it does exist and when i added a value to it it worked fine
We need a trigger on the asset object on update to check all assets.

 If on ALL Assets belonging to product family = "360 Suite" had their  Status = "Canceled" , then on Account, update the 360 Account stage (API Name = Account_Status__c )  to "Cancel".

please if anyone can help with this one I would be so grateful
Note : it requires SOSL
To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.
The Apex class must be called ContactAndLeadSearch and be in the public scope
The Apex class must have a public static method called searchContactsAndLeads
The method must accept an incoming string as a parameter
The method should then find any contact or lead that matches the string as part of either the first or last name
The method should finally use a return type of List<List< SObject>>


below is my code
public class ContactAndLeadSearch {
    
    public static List<List< SObject>> searchContactsAndLeads(String x){
        
        List<List<sObject>> searchList = [FIND {x} IN ALL FIELDS 
                   RETURNING Lead(FirstName,LastName),Contact(FirstName,LastName,Department)];
        
        return searchList;
    }
}
Create an Apex class that returns contacts based on incoming parameters.
For this challenge, you will need to create a class that has a method accepting two strings. The method searches for contacts that have a last name matching the first string and a mailing postal code matching the second. It gets the ID and Name of those contacts and returns them.

The Apex class must be called ContactSearch and be in the public scope
The Apex class must have a public static method called searchForContacts
The method must accept two incoming strings as parameters
The method should then find any contact that has a last name matching the first string, and mailing postal code (API name: MailingPostalCode) matching the second string
The method should finally return a list of Contact records of type List that includes the ID and Name fields



below is my code 

public class ContactSearch {
    
    public static List<String> searchForContacts(String x, String y){
        x1=x;
        y1=y;
        List<String> con = new List<String>();
        for (Contact[] tmp : [SELECT Id,Name FROM Contact where Name := x1 AND MailingPostalCode :=y1]) {
            con.add(tmp);
        }
        return con;
       
    }

}
the trigger should be on account to check the assets and if ALL the Assets belonging to product family = "bla bla " had their status "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c ) to "Cancel".

below is a trigger I wrote but it doesn't work

trigger cancelAsset on Account (after update) {

    
    List<Asset> suite = [Select Id ,Status from Asset where Product_Family__c = '360 Suite']; 
    List<Asset> tech = [Select Id ,Status from Asset where Product_Family__c = 'Ad Tech']; 
    for(Account acc:Trigger.new){
        
        Integer z=0;
        for(Integer i=0 ; i<= suite.size() ;i++){
            if(suite[i].Status == 'Canceled'){
              z++;
            }
        }
        
        if (z == suite.size()){
            acc.Account_Status__c = 'Cancel';
        }
        update acc;
    }
}