• Fabien Taillon
  • NEWBIE
  • 179 Points
  • Member since 2013
  • CTO
  • Texeï


  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 42
    Replies
Hi can anyone provide me sample code how to paginte in lightning components .Suppose if i have to show 10 records of account each time and i have 100 records in total . So how to paginate this in lightning
My class

public with sharing class AccountContactRoles {
    private final Contact acr;
 
    public AccountContactRoles(ApexPages.StandardController controller){
        this.acr = (Contact)controller.getRecord();
    }
 
    public List<AccountContactRole> acrs {
        get {
            if (acrs == null) {
                acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole
                    Where ContactId=:acr.Id];             
            }
            return acrs;
        }
        private set;
    }
}


my Test class

@isTest
private class TestAccountcontactroleClass{
    @isTest
    private static void testClass()
    {
    //Standard controller of Accountcontactrole
    //Create a new instance of Accountcontactrole
    Account acc = new Account(Name = 'Test Account');
    insert acc;
    Contact con = new Contact(LastName = 'Test Last Name', AccountId = acc.Id);
    insert con;
 
    AccountContactRole acr1 = new AccountContactRole();
                acr1.AccountId = acc.Id;
                acr1.ContactId = con.Id;
                acr1.Role = 'Test 1';
                acr1.IsPrimary=True;
            insert acr1;
    //Insert the object virtually


    //Create a new instance of standard controller
    ApexPages.StandardController sc = new ApexPages.standardController(con);

    AccountContactRoles controller = new AccountContactRoles(sc); 
    }
}




Here the problem is am getting only 57% code coverage ...so iwant to cover the below lines in test class...how to write a methosd in test class to cover those lines...the uncoverd  lines in my test class from class is  

public List<AccountContactRole> acrs {
        get {
            if (acrs == null) {
                acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole



The above class line is not coverd in my test class...ple help me ...thanks  in advance

Hi,

the following trigger was designed to prevent duplicate contacts on an account. But even when i edit the same contact and click save, the trigger acts and does not let me save the contact.

please help me figure out whats wrong with the trigger

trigger PreventDuplicateContact on Contact (after insert,after update) {
   
    if(trigger.isInsert || trigger.isUpdate)
    {
        Map<Id,List<Contact>> accMap = new Map<Id,List<Contact>>();
        List<Contact> contactList;
       
        for(Contact c: [Select Id,Email,accountId from Contact]){
            if(accMap.containsKey(c.accountId)){  
                accMap.get(c.accountId).add(c);
            }
            else{
                contactList = new List<Contact>();
                contactList.add(c);
                accMap.put(c.accountId,contactList);
            }      
        }
       
        for (Contact c : Trigger.new)
        {
            if(accMap.containsKey(c.accountId)){
                for(Contact con : accMap.get(c.accountId)){
                    if(c.Email == con.Email){
                       // c.Email.addError('Contact with this email address already exists.Please create a Contact Role. <a href=https://cs18.salesforce.com/02Z/e?parentId='+c.accountid+'\'>Create a Contact Role</a>',false);
                       String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ c.accountid +'"> Create a Contact Role  </a>';

c.Email.addError('Contact with this email address already exists.Please create a Contact Role'+ errorMsg,false);
                    }
                }
            }
        }
    }
}

  • September 26, 2014
  • Like
  • 0
I feel like I'm missing some obvious... 

Here is a Lighting test component based on https://www.lightningdesignsystem.com/components/data-tables#responsive-stacked-horizontal
 
<aura:component implements="flexipage:availableForAllPageTypes, force:appHostable">
    <ltng:require styles="/resource/SLDS0101/assets/styles/salesforce-lightning-design-system-ltng.css" />
    <table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
        <thead>
            <tr class="slds-text-heading--label">
                <th class="slds-row-select" scope="col">
                    <label class="slds-checkbox" for="select-all">
                        <input name="checkbox" type="checkbox" id="select-all" />
                        <span class="slds-checkbox--faux"></span>
                        <span class="slds-form-element__label slds-assistive-text">select all</span>
                    </label>
                </th>
                <th class="slds-is-sortable" scope="col">
                    <span class="slds-truncate">Opportunity Name</span>
                    <button class="slds-button slds-button--icon-bare">
                        <span class="slds-assistive-text">Sort</span>
                    </button>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Account Name</span>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Close Date</span>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Stage</span>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Confidence</span>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Amount</span>
                </th>
                <th scope="col">
                    <span class="slds-truncate">Contact</span>
                </th>
                <th class="slds-row-action" scope="col">
                    <button class="slds-button slds-button--icon-border-filled slds-button--icon-x-small">
                        <span class="slds-assistive-text">Show More</span>
                    </button>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr class="slds-hint-parent">
                <td class="slds-row-select">
                    <label class="slds-checkbox" for="select-row1">
                        <input name="select-row1" type="checkbox" id="select-row1" />
                        <span class="slds-checkbox--faux"></span>
                        <span class="slds-form-element__label slds-assistive-text">select row1</span>
                    </label>
                </td>
                <th data-label="opportunity-name" role="row"><a href="#" class="slds-truncate">Acme 25</a></th>
                <td data-label="account"><a href="#" class="slds-truncate">Acme</a></td>
                <td data-label="activity">
                    <span class="slds-truncate">4/14/2015</span>
                </td>
                <td data-label="stage">
                    <span class="slds-truncate">Prospecting</span>
                </td>
                <td data-label="confidence">
                    <span class="slds-truncate">20%</span>
                </td>
                <td data-label="amount">
                    <span class="slds-truncate">$25k</span>
                </td>
                <td data-label="contact">
                    <span class="slds-truncate">--</span>
                </td>
                <td class="slds-row-action">
                    <button class="slds-button slds-button--icon-border-filled slds-button--icon-x-small">
                        <span class="slds-assistive-text">Show More</span>
                    </button>
                </td>
            </tr>
            <tr class="slds-hint-parent">
                <td class="slds-row-select">
                    <label class="slds-checkbox" for="select-row2">
                        <input name="select-row2" type="checkbox" id="select-row2" />
                        <span class="slds-checkbox--faux"></span>
                        <span class="slds-form-element__label slds-assistive-text">select row2</span>
                    </label>
                </td>
                <th data-label="opportunity-name" role="row"><a href="#" class="slds-truncate">Rohde Corp 30</a></th>
                <td data-label="account"><a href="#" class="slds-truncate">Rohde Corp</a></td>
                <td data-label="activity">
                    <span class="slds-truncate">6/18/2015</span>
                </td>
                <td data-label="stage">
                    <span class="slds-truncate">Prospecting</span>
                </td>
                <td data-label="confidence">
                    <span class="slds-truncate">40%</span>
                </td>
                <td data-label="amount">
                    <span class="slds-truncate">$30k</span>
                </td>
                <td data-label="contact"><a href="#" class="slds-truncate">achoi@rohdecorp.com</a></td>
                <td class="slds-row-action">
                    <button class="slds-button slds-button--icon-border-filled slds-button--icon-x-small">
                        <span class="slds-assistive-text">Show More</span>
                    </button>
                </td>
            </tr>
        </tbody>
    </table>
</aura:component>
Create an app like:
 
<aura:application >
<ltng:require styles="/resource/SLDS0101/assets/styles/salesforce-lightning-design-system-ltng.css" />
    <div class="slds" style="margin-top:10px;margin-left:10px;margin-right:10px">
        <c:CSSTest />
    </div>
</aura:application>

... loads up on my desktop browser using "Preview" from the developer console, no problem. All responsive and styled.

However, when I add this using the Lighting App Building to make a new "app" for Salesforce1, it loses the Lightning Design System styles. Any idea what I'm missing and/or doing wrong? Is there an embedded "salesforce-lightning-design-system-ltng.css" in Salesforce1 that I am supposed to reference? Or am I supposed to do something else fancy?

From what I can tell none of the tutorials on Trailhead or elsewhere cover this, so  any advice is most appreciated.

Thanks!
 
Hello All,

We have implemented functionality to accept user input. In this we have single select questions for which we are using radio input.
Following is the code : 
<aura:renderIf isTrue='{!question.answer == opt}'>
<input type="radio" value="{!question.id}" name="{!questionNumber}" onchange="{!c.onRadioSelect}"  title="{!opt}" checked='checked'/>{!opt}
<aura:set attribute='else'>
<input type="radio" value="{!question.id}" name="{!questionNumber}" onchange="{!c.onRadioSelect}"  title="{!opt}"/>{!opt}
</aura:set>
</aura:renderIf>


Here, question.answer = selected answer ( Saved in object )
{!opt} = label of input radio 

When we are trying to load lightning component for existing result, it is throwing following error.
Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Invalid component tried calling function [get] with arguments [v.items.0]



User-added image

We have also tried to use <ui:inputRadio label="Yes"/> , but design is not working for this properly, also it won't render on iPhone properly.

If anyone has faced similar issue or has any idea , please let me know.
Thanks ,
  • November 05, 2015
  • Like
  • 0
I can't get my app to work when I include a force:outputField component in it. For example, if I have the following then it's OK and I get the correct value rendered in my app:
<ui:outputText aura:id="pcode" value="{!v.product.productCode}"/>
...but if I change it to use force:outputField like so:
<force:outputField aura:id="pcode" value="{!v.product.productCode}"/>
...then I get the following failure when the app tries to render the component where I have the outputField:

"Assertion Failed!: Abstract component without provider def cannot be instantiated : markup://force:outputField : undefined. Please try again."

Is there something I am missing? This outputField component does exist in the developer reference (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_force_outputField.htm). 
Hi can anyone provide me sample code how to paginte in lightning components .Suppose if i have to show 10 records of account each time and i have 100 records in total . So how to paginate this in lightning
How to get Sandbox Name from Apex?
While developing in Apex, I need to retrieve sandbox name in my code.  How do I do this in Apex?  Thanks in advance.
Team,

I have created the following Apex Class Extension and VF Page which when placed on our Account Page Layouts gives me the following error...

Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Account.Account_Name__c

I am a little confused as I am a beginner with coding, but I am thinking I am requesting the correct field.  

Please help me by looking over my code as follows... Thank you for your time, and I thank you in advance to whoever can save the day! 

Shawn


Apex Class

/*
Class Name:
Description: This Class is used to display Bill To Address details in Account page as in-line visual force page.
Date Created: 12-11-2014.
*/

public class PopulatebilltoInfoHandler
{
    Account ac= new Account();
    List<Bill_to_Address__c> roomLoclist = new List<Bill_to_Address__c>();
    
    
    private Integer counter=0;
    private Integer list_size=2000;
    public Id accId;
    private Integer total_size;
    
    public PopulatebilltoInfoHandler(ApexPages.StandardController controller)
    {
        ac = (Account)controller.getRecord();
        accId = ac.Account_Name__c;
        //populateBilltoInfo();
        total_size = [Select count() From Bill_to_Address__c Where (Bill_to_Address__c.Account_Name__c = :ac.Account_Name__c)];
    }
    
    public List<Bill_to_Address__c> getroomList()
    {
        try
        {
            roomLoclist = [Select Id,Name,Customer_Number__c,City__c,State__c,Zip__c
                                     From Bill_to_Address__c]; 
                                    
        }
        catch(Exception e){system.debug('Query Exception'+e.getMessage());}
        if(roomLoclist != null && roomLoclist.size()>0)
            return roomLoclist;
        else
            return roomLoclist;
       
    }
    
     public PageReference Previous()
    {
        counter-=list_size;
        return null;
    }
    
    public PageReference Next()
    {
        counter+=list_size;
        return null;
    }
    
    public Boolean getDisablePrevious()
    {
        if(counter >0)
            return false;
        else
            return true;
    }
    
    public Boolean getDisableNext()
    {
        if(counter+list_size < total_size)
            return false;
        else return true;
    }


}


VF Page Code

<apex:page standardcontroller="Account" extensions="PopulatebilltoInfoHandler" id="lolinePage">
<apex:stylesheet value="{!$Resource.pdfresources}"/>



<apex:pageBlock title="Bill-To Details">

    <apex:pageBlockTable value="{!roomList}" var="loline" id="lolinedetails">
        <apex:column >
            <apex:facet name="header">Bill To Address</apex:facet> 
                 <a href="/{!loline.Name}" target="_parent">{!loline.Name}</a>
        </apex:column>
        
        <apex:column >
                <apex:facet name="header">City</apex:facet>
                <apex:outputText value="{!loline.City__c}"/>
        </apex:column>
        
        <apex:column > 
                <apex:facet name="header">State</apex:facet>
                <apex:outputText value="{!loline.State__c}"/>
        </apex:column>
        
        <apex:column > 
                <apex:facet name="header">Zip</apex:facet>
                <apex:outputField value="{!loline.Zip__c}"/>
        </apex:column>
        
        
   

    </apex:pageBlockTable>

    
   
        

    
</apex:pageBlock>

  <apex:outputPanel id="myButtons"  layout="block">
    <apex:form >
        <apex:panelGrid cellpadding="7" columns="4">
        
            <apex:commandButton value="<Previous" action="{!Previous}" disabled="{!DisablePrevious}" reRender="lolinedetails,myButtons"/>
            <apex:commandButton value="Next>" action="{!Next}" disabled="{!DisableNext}" reRender="lolinedetails,myButtons"/>
        
        </apex:panelGrid>
    </apex:form>
    </apex:outputPanel>
</apex:page>
Hi all, i am trying to put a test class for a controller  into a production org, however I am getting the error message:

System.LimitException: Too many query rows: 50001 Class.MascotController.getContacts: line 12, column 1 Class.MascotController.<init>: line 7, column 1 Class.MascotControllerTestClass.MascotController: line 14, column 1

Is there something I need to add to the code in order for this to work?
Thanks

Controller:
public class MascotController 
{
   public List<Contact> contacts{get;set;}

   public MascotController()
   {
        getContacts();
   }

   public void getContacts()
   {
        Integer count = [SELECT COUNT() FROM Contact];
        Integer rand = Math.floor(Math.random() * count).intValue();
        Set<Id> contactIds = new Set<Id>();
        contacts = new List<Contact>();

        for(CampaignMember cm : [Select Id, ContactId from CampaignMember where Status = 'Sent' and Campaign.Name = '2014/15 Mascot Data'])
        {
           contactIds.add(cm.ContactId);
        }
        List<String> orderBys = new List<String>{'Email Asc','Email Desc','Lastname Asc','Firstname Desc','LastModifiedDate Desc','LastModifiedDate Asc','CreatedDate Asc','CreatedDate Desc','Id Asc','Id Desc'};

        String orderBy = orderBys.get(Math.mod(rand,orderBys.size()));

        contacts = Database.query('Select Name From Contact where ID in :contactIds Order By ' + orderBy + ' Limit 2 OFFSET :rand');
    }
}

Test Class:
@isTest(SeeAllData=true)
private class MascotControllerTestClass {
     static testMethod void MascotController() {
        Account ac = new Account(name ='Daniel') ;
        insert ac; 
        Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
        insert con;  
        Campaign camp = new Campaign (Name = '2014/15 Mascot Data');

        insert camp;
        CampaignMember  capMember = new CampaignMember(Status ='To be Called', contactid=con.id, CampaignId = camp.id);
        insert capMember;
        PageReference pageref = Page.mascotPage;
        MascotController cont = new MascotController();
     }
}


 
Hello,
 I have created a Lightning Component , I can only access the lightning tab when accessing Salesforce1 from my iPhone browser .If I start the Salesforce1 iPhone app it also shows up in the left navigation, but when I click it I just see a loading spinner and nothing ever happens. how to deploy it to salesforce1 mobile app
I'm working through Expenses example in the Dev Guide and see "v." and "c." in several locations but they aren't things that are declare anywhere.

Are these well-known objects that have to be referenced via "v" and "c"?  Like mayb "v" is view and "c" is controller" or something like that?

I'm curious if the code could be altered and the "v." and "c." terms could be changed if they are declared somewhere or if I'm coding in this style, must I use objects referred to by the specific named "v" and "c".
My class

public with sharing class AccountContactRoles {
    private final Contact acr;
 
    public AccountContactRoles(ApexPages.StandardController controller){
        this.acr = (Contact)controller.getRecord();
    }
 
    public List<AccountContactRole> acrs {
        get {
            if (acrs == null) {
                acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole
                    Where ContactId=:acr.Id];             
            }
            return acrs;
        }
        private set;
    }
}


my Test class

@isTest
private class TestAccountcontactroleClass{
    @isTest
    private static void testClass()
    {
    //Standard controller of Accountcontactrole
    //Create a new instance of Accountcontactrole
    Account acc = new Account(Name = 'Test Account');
    insert acc;
    Contact con = new Contact(LastName = 'Test Last Name', AccountId = acc.Id);
    insert con;
 
    AccountContactRole acr1 = new AccountContactRole();
                acr1.AccountId = acc.Id;
                acr1.ContactId = con.Id;
                acr1.Role = 'Test 1';
                acr1.IsPrimary=True;
            insert acr1;
    //Insert the object virtually


    //Create a new instance of standard controller
    ApexPages.StandardController sc = new ApexPages.standardController(con);

    AccountContactRoles controller = new AccountContactRoles(sc); 
    }
}




Here the problem is am getting only 57% code coverage ...so iwant to cover the below lines in test class...how to write a methosd in test class to cover those lines...the uncoverd  lines in my test class from class is  

public List<AccountContactRole> acrs {
        get {
            if (acrs == null) {
                acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole



The above class line is not coverd in my test class...ple help me ...thanks  in advance
I'm not really a javascript developer but as I understood it I need to have some/good javascript skills. Is there a recommendation for tutorial for learning javascript as it relates to Lightning?
Is ligtning builder requestable for pilot yet?

Does anyone know if there's a way to get the current sandbox name in apex short of screen scraping it from the upper right of a standard page? Thanks!

 

Scott

Is there any way to check if a list contains a certain element?  I looked at the List functions and did not see any contain() function like Java has, so I was wondering how other people are handling this.
 
Thanks