• sf ost
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 17
    Replies
Hi all,

I am unable to get the code coverage for below trigger. All lines are covered except 8 and 9 lines.

Scinario: Only once record can be Active for a User. Leader__c is in Lookup-Relationship with User. Also if I update one record "Active__c = True" remaining records of that User should be updated (Active__c = False).
trigger OneRecordCanBeActive on Leader__c(after insert, before update) {

	if(checkRecursive.runOnce()){
		List<Leader__c> lList = new List<Leader__c>();
		List<Leader__c> gAccs = [select Id, Active__c, User__c from Leader__c where Id not in :Trigger.new and Active__c = True and User__c = :UserInfo.getUserId()];
			
			for(Leader__c l : gAccs){
				l.Active__c = False;
				lList.add(l);
			}
			update lList;
	}
}

My Test Class:
@isTest
private class OneRecordCanBeActive_Test {

	private static testMethod void test() {
	    
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
        
        User u = new User();
            u.Alias = 'SysAdmin';
            u.Email='sysAdmin@testorg.com';
            u.EmailEncodingKey='UTF-8';
            u.LastName='Testing';
            u.LanguageLocaleKey='en_US';
            u.LocaleSidKey='en_US';
            u.ProfileId = p.Id;
            u.TimeZoneSidKey='America/Los_Angeles';
            u.UserName='gaccuser@testorg.com';
        Insert u;
            
        Leader__c l1 = new Leader__c();
            l1.Active__c = True ;
            l1.User__c = u.id;
        Insert l1;
        
        Leader__c l2 = new Leader__c();
            l2.Active__c = True ;
            l2.User__c = u.id;
        Insert l2;
		
        l1.Active__c = True ;
        Update l1;
	}

}

Thankyou.
  • August 31, 2016
  • Like
  • 0
Hi all,

I am getting a response from REST Api consisting of names and "nextpagetoken". I dont want to store this response in salesforce. Am adding these names to the WrapperList and displying them on visualforce page. I limited my callout to query only 10 names. When clicked on GetMore commandButton (making 2nd callout using nextpagetoken) i need to add the next 10 names to the existing WrapperList and show total 20 names on VF page.

Suggestions are appretiated. Thanks.
  • August 15, 2016
  • Like
  • 0
Hi all,

I am unable to know, how to create different login pages for 2 different communities which are same org. Also if i use same login screen for both how to differentiate the community user with respect to communities?

Help me in this.
  • April 21, 2016
  • Like
  • 0
Hi All,

I created 2 communities in the same salesforce org having same login screens. Also created a single community user, same community user for both. Community user is logged into 1st community and when he tries to open the 2nd community in another tab he is getting this error shown below.

****** Error: __MISSING LABEL__ PropertyFile - val SiteLoginFailureException not found in section Exception ******

How to overcome this?
  • April 21, 2016
  • Like
  • 0
Hi guys,

I wanted to change the color of the progress bar based on fields. How can I acheive this? Below image is the reference..

User-added image
  • April 16, 2016
  • Like
  • 0
I need to display products in Order object. We are using 'Order Products (Pricebook)' standard object which is in lookup with 'Orders'. But i am unable to find api name of 'Order Products' standard object to query them products selected from pricebook.

I need to show both "order details" and "products in order (Order Products)" details.

My contoller code. Working for only retriving orders. Not working for quering order products (Pricebook)
 
public with sharing class OrdersController {

    public List<Order> orderList {get;set;}
    
    public OrdersController(){
        orderList = new List<Order>();
    }
    
    public List<Order> getOrders(){
        return [SELECT OrderNumber, TotalAmount, Status (Select Product2Id, Product2.Name From PricebookEntry__r Where Product2Id =: productdet) FROM Order WHERE OwnerID=: UserInfo.getUserId()];
    }
 }
My VF code:
 
<apex:page controller="OrdersController" showHeader="false">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
    
jQuery.noConflict();
    
    jQuery(document).ready(function($) {
        
        $("#pnl_details").hide();
 
        $('#viewDetails').click(function () {
            if ($("#pnl_details").is(":hidden")) {
                $("#pnl_details").slideDown("slow");
                $("#viewDetails").html("Show Less Details");
                 return false;
            } else {
                $("#pnl_details").hide("slow");
                $("#viewDetails").html("Show More Details");
             return false;
            }
            });         
    });
</script>

  <apex:pageBlock >
  <!-- <apex:repeat value="{!Orders}" var="owd">
            ['{!owd.OrderNumber}','{!owd.TotalAmount}','{!owd.Status}']
</apex:repeat> -->
  <apex:pageBlockSection title="Orders" id="pnl_details" columns="1">
        <apex:pageBlockTable value="{!orders}" var="o">
      
            <!-- <apex:column headerValue="Order Number">
                <apex:commandLink action="{!URLFOR($Action.Order.View, o.id)}" value="{!o.OrderNumber}"/>
            </apex:column> -->
            <apex:column value="{!o.OrderNumber}"/>
            <apex:column value="{!o.TotalAmount}" />
            <apex:column value="{!o.Status}" />
            
      </apex:pageBlockTable>
  </apex:pageBlockSection>
<apex:pageBlockSection columns="1">
    <apex:relatedList list="Pricebook2 " />
</apex:pageBlockSection>
  </apex:pageBlock>

</apex:page>



help me in this.
 
  • April 13, 2016
  • Like
  • 0
I need to display products in Order object. We are using 'Order Products' standard object which is in lookup with 'Orders'. But i am unable to find api name of 'Order Products' standard object to query them products.

I need to show both "order details" and "products in order (Order Products)" details.

help me in this.
  • April 12, 2016
  • Like
  • 0
Hi guys,

Am new to salesforce. I need to display Order and Order products on a vf page based on user logged-in. Both are standard objects. Order and Order products are in lookup. Help me regarding this...
  • April 12, 2016
  • Like
  • 0
Hi all,
  • Create a class
  • Declare and populate array of string containing month names viz. January, February ….
  • Create a method to return a string in below format :
January > February > …
Show it on VF page.

I am output result as [January,February,March]. but here i need output result on vf page as January > February>March. How to achive this.

Apex Code:
public class months{
  String[] arrayItems;

   public PageReference myArrayItems()
    {
       arrayItems = new String[] {'January','February','March','April','May','June','July','August','September','November','December'};
       return null;
    }

    public String[] getitems()
     {
       return arrayItems ;
     }  
}

VF page:
<apex:page showHeader="false" controller="months">
<apex:form >
        
        <apex:outputText value="{!items}" id="mn"/> <br/>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

how to acheive this ?
  • March 25, 2016
  • Like
  • 0
Hi all,

When ever the button "Click" is clicked. The value should increment to 0,1,2,3,4,...etc,. Should not use JavaScript. Use only controller and vf page.

I have tried but, no value is incrementing. Once go through the below code.

VF Code:
<apex:page showHeader="false" controller="increment">
<apex:form >
 <apex:commandButton value="Click" action="{!display}"/>
</apex:form>
</apex:page>

Apex Class:
public class increment{

    integer numb;
    integer i;

    public void display(){
    
       numb = 100;
       
    for(i=0; i<numb; i++){
        i=i+1;
        System.debug(i);
        
    } 
    
    }

}

What is wrong in my code?
  • March 24, 2016
  • Like
  • 1
Hi Guys,

As a part of learning salesforce i got some errors in testClass. Need help on those errors. why they got ?

Error: Compile Error: Method is not visible: VerifyDate.DateWithin30Days(Date, Date) at line 31 column 21, and
Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.SetEndOfonMonthDate(Date) at line 40 column 21

Apex Class:
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;
    }

}

and below is my testClass:
@isTest

private class TestVerifyDate{

    @isTest static void TVD1(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');

        Date TVD1 = VerifyDate.CheckDates(Date1, Date2);
        System.assertEquals(Date2, TVD1);

    }
    
    @isTest static void TVD2(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');
        Date firstDayOfMonth = System.today().toStartOfMonth();

        Date TVD2 = VerifyDate.CheckDates(Date1,Date2);
        System.assertEquals(Date1.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1), TVD2);

    }
    
    @isTest static void TVD3(){
    
      	Date Date1 = Date.parse('1/03/16');
       	Date Date2 = Date.parse('12/03/16');
        
       	Date TVD3 = VerifyDate.DateWithin30Days(Date1, Date2);
       	System.assertEquals(false, TVD3);

   }
    
   @isTest static void TVDL(){
    
       	Date Date1 = Date.parse('1/03/16');
       
        Date TVDL = VerifyDate.SetEndOfonMonthDate(Date1);
        System.assertEquals(Date1, TVDL);

   }


}

any modifications to the testClass ? Help me regarding this.
 
  • March 18, 2016
  • Like
  • 0
Hi Guys,

I am getting this error while clearing a task in trailhead.

Challenge Not yet complete... here's what's wrong:
Setting 'Match_Billing_Address__c' to true did not update the records as expected.

Question: For this challenge, you need to create a trigger that, before insert or update, checks for a checkbox, and if the checkbox field is true, sets the Shipping Postal Code (whose API name is ShippingPostalCode) to be the same as the Billing Postal Code (BillingPostalCode).
  1. The Apex trigger must be called 'AccountAddressTrigger'.
  2. The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
  3. With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.
My code is below..
 
trigger AccountAddressTrigger on Account (before insert, before update) {

if(trigger.isInsert && trigger.isBefore)
{
   for( Account a : Trigger.New)
    {
        if(a.Match_Billing_Address__c == true && a.ShippingPostalCode!=null)
          {

                 a.ShippingPostalCode= a.BillingPostalCode;
             
           }
      }
}
}

What is wrong in the code... ?
 
  • March 15, 2016
  • Like
  • 0
Hi,

There are two Custom Objects, Object1 (Parent), Object2 (Child). Both are in MD relationship.

Object1 (Parent) has a picklist field "Statuc__c" with values InProgress & Completed.
Object2 (Child) has a field of CheckBox datatype "Completed__c".

Now. When the value of checkbox Completed__c is true in all the records of an associated parent record. then only the filed Status__c in Object1 should change to the value Completed.

How can I achieve this?

Your suggestion will be appreciated.
  • January 05, 2016
  • Like
  • 0
Hi,

There are two Custom Objects, Object1 (Parent), Object2 (Child). Both are in MD relationship.

Object1 (Parent) has a picklist field "Statuc__c" with values InProgress & Completed.
Object2 (Child) has a field of CheckBox datatype "Completed__c".

Now. When the value of checkbox Completed__c is true in all the records of an associated parent record. then only the filed Status__c in Object1 should change to the value Completed.

How can I achieve this?

Your suggestion will be appreciated.
  • January 05, 2016
  • Like
  • 0
Hi all,

When ever the button "Click" is clicked. The value should increment to 0,1,2,3,4,...etc,. Should not use JavaScript. Use only controller and vf page.

I have tried but, no value is incrementing. Once go through the below code.

VF Code:
<apex:page showHeader="false" controller="increment">
<apex:form >
 <apex:commandButton value="Click" action="{!display}"/>
</apex:form>
</apex:page>

Apex Class:
public class increment{

    integer numb;
    integer i;

    public void display(){
    
       numb = 100;
       
    for(i=0; i<numb; i++){
        i=i+1;
        System.debug(i);
        
    } 
    
    }

}

What is wrong in my code?
  • March 24, 2016
  • Like
  • 1
Hi all,

I am unable to get the code coverage for below trigger. All lines are covered except 8 and 9 lines.

Scinario: Only once record can be Active for a User. Leader__c is in Lookup-Relationship with User. Also if I update one record "Active__c = True" remaining records of that User should be updated (Active__c = False).
trigger OneRecordCanBeActive on Leader__c(after insert, before update) {

	if(checkRecursive.runOnce()){
		List<Leader__c> lList = new List<Leader__c>();
		List<Leader__c> gAccs = [select Id, Active__c, User__c from Leader__c where Id not in :Trigger.new and Active__c = True and User__c = :UserInfo.getUserId()];
			
			for(Leader__c l : gAccs){
				l.Active__c = False;
				lList.add(l);
			}
			update lList;
	}
}

My Test Class:
@isTest
private class OneRecordCanBeActive_Test {

	private static testMethod void test() {
	    
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
        
        User u = new User();
            u.Alias = 'SysAdmin';
            u.Email='sysAdmin@testorg.com';
            u.EmailEncodingKey='UTF-8';
            u.LastName='Testing';
            u.LanguageLocaleKey='en_US';
            u.LocaleSidKey='en_US';
            u.ProfileId = p.Id;
            u.TimeZoneSidKey='America/Los_Angeles';
            u.UserName='gaccuser@testorg.com';
        Insert u;
            
        Leader__c l1 = new Leader__c();
            l1.Active__c = True ;
            l1.User__c = u.id;
        Insert l1;
        
        Leader__c l2 = new Leader__c();
            l2.Active__c = True ;
            l2.User__c = u.id;
        Insert l2;
		
        l1.Active__c = True ;
        Update l1;
	}

}

Thankyou.
  • August 31, 2016
  • Like
  • 0
Hi all,

I am getting a response from REST Api consisting of names and "nextpagetoken". I dont want to store this response in salesforce. Am adding these names to the WrapperList and displying them on visualforce page. I limited my callout to query only 10 names. When clicked on GetMore commandButton (making 2nd callout using nextpagetoken) i need to add the next 10 names to the existing WrapperList and show total 20 names on VF page.

Suggestions are appretiated. Thanks.
  • August 15, 2016
  • Like
  • 0
Hi guys,

Am new to salesforce. I need to display Order and Order products on a vf page based on user logged-in. Both are standard objects. Order and Order products are in lookup. Help me regarding this...
  • April 12, 2016
  • Like
  • 0
Hi all,
  • Create a class
  • Declare and populate array of string containing month names viz. January, February ….
  • Create a method to return a string in below format :
January > February > …
Show it on VF page.

I am output result as [January,February,March]. but here i need output result on vf page as January > February>March. How to achive this.

Apex Code:
public class months{
  String[] arrayItems;

   public PageReference myArrayItems()
    {
       arrayItems = new String[] {'January','February','March','April','May','June','July','August','September','November','December'};
       return null;
    }

    public String[] getitems()
     {
       return arrayItems ;
     }  
}

VF page:
<apex:page showHeader="false" controller="months">
<apex:form >
        
        <apex:outputText value="{!items}" id="mn"/> <br/>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

how to acheive this ?
  • March 25, 2016
  • Like
  • 0
Hi all,

When ever the button "Click" is clicked. The value should increment to 0,1,2,3,4,...etc,. Should not use JavaScript. Use only controller and vf page.

I have tried but, no value is incrementing. Once go through the below code.

VF Code:
<apex:page showHeader="false" controller="increment">
<apex:form >
 <apex:commandButton value="Click" action="{!display}"/>
</apex:form>
</apex:page>

Apex Class:
public class increment{

    integer numb;
    integer i;

    public void display(){
    
       numb = 100;
       
    for(i=0; i<numb; i++){
        i=i+1;
        System.debug(i);
        
    } 
    
    }

}

What is wrong in my code?
  • March 24, 2016
  • Like
  • 1
Hi Guys,

As a part of learning salesforce i got some errors in testClass. Need help on those errors. why they got ?

Error: Compile Error: Method is not visible: VerifyDate.DateWithin30Days(Date, Date) at line 31 column 21, and
Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.SetEndOfonMonthDate(Date) at line 40 column 21

Apex Class:
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;
    }

}

and below is my testClass:
@isTest

private class TestVerifyDate{

    @isTest static void TVD1(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');

        Date TVD1 = VerifyDate.CheckDates(Date1, Date2);
        System.assertEquals(Date2, TVD1);

    }
    
    @isTest static void TVD2(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');
        Date firstDayOfMonth = System.today().toStartOfMonth();

        Date TVD2 = VerifyDate.CheckDates(Date1,Date2);
        System.assertEquals(Date1.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1), TVD2);

    }
    
    @isTest static void TVD3(){
    
      	Date Date1 = Date.parse('1/03/16');
       	Date Date2 = Date.parse('12/03/16');
        
       	Date TVD3 = VerifyDate.DateWithin30Days(Date1, Date2);
       	System.assertEquals(false, TVD3);

   }
    
   @isTest static void TVDL(){
    
       	Date Date1 = Date.parse('1/03/16');
       
        Date TVDL = VerifyDate.SetEndOfonMonthDate(Date1);
        System.assertEquals(Date1, TVDL);

   }


}

any modifications to the testClass ? Help me regarding this.
 
  • March 18, 2016
  • Like
  • 0
Hi,

There are two Custom Objects, Object1 (Parent), Object2 (Child). Both are in MD relationship.

Object1 (Parent) has a picklist field "Statuc__c" with values InProgress & Completed.
Object2 (Child) has a field of CheckBox datatype "Completed__c".

Now. When the value of checkbox Completed__c is true in all the records of an associated parent record. then only the filed Status__c in Object1 should change to the value Completed.

How can I achieve this?

Your suggestion will be appreciated.
  • January 05, 2016
  • Like
  • 0