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

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 34
    Replies
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;
}
}
@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
@isTest

private class AssetTriggerTest{
    @testSetup 
     static void testclass(){
         List<sObject> ls = Test.loadData(Asset.sObjectType, 'AssetTest2');
        List<sObject> lsa = Test.loadData(Account.sObjectType, 'AccountTestF');

         
    }
    
    public static testMethod void test(){

       Map<id,Asset> a = New Map <id, Asset >([select Product_Family__c , Status from Asset ]);
       List<Asset> l = a.values();
        for( Asset ast:l){
            
            if(ast.Product_Family__c == '360'){
                
                ast.Status = 'Canceled';
            }
        }
        update l;
        
        Account acc=[select Account_Status__c from Account limit 1];
        system.assertEquals(acc.Account_Status__c,'Cancel');
       
        
    }

    
}




it's giving me this error :
System.StringException: Error in CSV resource 'AssetTestF' line 2: Cannot set the value of a calculated field
How to add an asset to a certain account in apex?

@isTest

private class AssetTriggerTest{
    @isTest static void testclass(){
     
        Account acc = new Account();
        acc.Name = 'farah test';
        
        
        insert acc;
    }
    
}
We need a trigger on the asset object on update to check all assets.

 If 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".

The trigger should first check the status of the asset (Trigger.new ) , if it is cancelled then we will do the code. The trigger should also check the (trigger.old) status, if it is anything other than cancelled then also continue with the code

please if anyone can help with this one I would be so grateful
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
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".
<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;
    }
}

 
the trigger should be on account on update, to check the assets and if all Assets belonging to product family = "bla bla "  have their status "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c )  to "Cancel". 
Create a method for inserting accounts.

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.

The Apex class must be called AccountHandler and be in the public scope
The Apex class must have a public static method called insertNewAccount
The method must accept an incoming string as a parameter, which will be used to create the Account name
The method must insert the account into the system and then return the record
The method must also accept an empty string, catch the failed DML and then return null