• adflint
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies
Hi All,

I'm trying to create a Lightning Component for a Global Quick Action in order to create a detail object "Billable__c" for a Master Object "Project__c".

I've got it working in Salesforce Lightning Experience, however I'm having issues using the global quick action in the Salesforce1 app.  I'm getting the following error:
 
Error in $A.getCallback() [undefined is not an object (evaluating 'a.attributes')]
Callback failed: serviceComponent://ui.chatter.components.aura.components.forceChatter.chatter.QuickActionLoaderController/ACTION$getQuickActions
(https://stratusg.lightning.force.com/auraFW/javascript/xH6sVFQUmvLYLsBsK3q02Q/aura_prod.js:2)

Here is my component:
 
<aura:component implements="force:lightningQuickActionWithoutHeader" controller="HoursController" access="GLOBAL">
    <aura:attribute name="newBillable" type="Billable__c" default="{ 'sobjectType': 'Billable__c'}"/>
    <aura:attribute name="options" type="list" default="[{ 'class': 'optionClass', label: '- None -', value: '' }]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div class="slds-page-header" role="banner">
        <h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left">Log Hours</h1>
    </div>
    <label class="slds-form-element__label">Number of Hours</label>
    <force:inputField aura:id="hours" value="{!v.newBillable.Numer_of_Hours__c}" />
    <lightning:select aura:id="project" name="project" label="Project" value="{!v.newBillable.Project__c}" required="true">
    	<aura:iteration items="{!v.options}" var="item" >
            <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
        </aura:iteration>
    </lightning:select>
    <label class="slds-form-element__label">Date</label>
    <force:inputField aura:id="date" value="{!v.newBillable.Date__c}" />
    <label class="slds-form-element__label">Description</label>
    <force:inputField aura:id="desc" value="{!v.newBillable.Description__c}" />
    <lightning:button label="Save Billable" onclick="{!c.handleSaveBillable}" variant="brand" class="slds-m-top-medium"/>
</aura:component>

Here is my Controller:
 
({
    doInit : function (component, event, helper) {
        helper.loadProjects(component);
    },
    
	handleSaveBillable : function(component, event, helper) {
        var newBillable = component.get("v.newBillable");
        helper.upsertBillable(component, newBillable);
    }
})
Helper:
 
({
    loadProjects : function(component) {
        var action = component.get("c.getProjects");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                //component.set("v.projects", response.getReturnValue());
                //var projects = component.get("v.projects");
        		var projects = response.getReturnValue();
                var opts = new Array();
        		opts.push({value: "", label: "- None -"});
                for(var i=0; i<projects.length; i++){
                    var p = projects[i];
                    console.log(p);
                    opts.push({value: p.Id, label: p.Name});
                }
                console.log(opts);
                component.set("v.options", opts);
            } else {
                console.log('Problem getting Projects, response state: '+state);
            }
        });
        $A.enqueueAction(action);
    },
    
    upsertBillable : function(component, billable) {
        var action = component.get("c.saveBillable");
        action.setParams({
            "billable": billable
        });
        $A.enqueueAction(action);
    }
})

Apex Controller:
 
public with sharing class HoursController {
	
    @AuraEnabled
    public static List<Project__c> getProjects(){
        return [SELECT Id, Name FROM Project__c WHERE Status__c = 'Active'];
    }
    
    @auraEnabled
    public static Billable__c saveBillable(Billable__c billable){
        upsert billable;
        return billable;
    }
}

Any help is appreciated.

 
Is it possible to have a visualforce page iin Salesforce1 with a hyperlink that opens a URL directly in Safari (not in the child browser from Salesforce1)

I tried using the javascript:

onclick="sforce.one.navigateToURL('http://google.com');"

but in order for this to open in Safari, I have to click "open in Safari".

the reason I need to do this is because I want to give our users a link in Salesforce1 to download a HTML5 web app to their home screen.

Any help is greatly appreciated!

- Anthony
Hi All,

I'm trying to create a Lightning Component for a Global Quick Action in order to create a detail object "Billable__c" for a Master Object "Project__c".

I've got it working in Salesforce Lightning Experience, however I'm having issues using the global quick action in the Salesforce1 app.  I'm getting the following error:
 
Error in $A.getCallback() [undefined is not an object (evaluating 'a.attributes')]
Callback failed: serviceComponent://ui.chatter.components.aura.components.forceChatter.chatter.QuickActionLoaderController/ACTION$getQuickActions
(https://stratusg.lightning.force.com/auraFW/javascript/xH6sVFQUmvLYLsBsK3q02Q/aura_prod.js:2)

Here is my component:
 
<aura:component implements="force:lightningQuickActionWithoutHeader" controller="HoursController" access="GLOBAL">
    <aura:attribute name="newBillable" type="Billable__c" default="{ 'sobjectType': 'Billable__c'}"/>
    <aura:attribute name="options" type="list" default="[{ 'class': 'optionClass', label: '- None -', value: '' }]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div class="slds-page-header" role="banner">
        <h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left">Log Hours</h1>
    </div>
    <label class="slds-form-element__label">Number of Hours</label>
    <force:inputField aura:id="hours" value="{!v.newBillable.Numer_of_Hours__c}" />
    <lightning:select aura:id="project" name="project" label="Project" value="{!v.newBillable.Project__c}" required="true">
    	<aura:iteration items="{!v.options}" var="item" >
            <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
        </aura:iteration>
    </lightning:select>
    <label class="slds-form-element__label">Date</label>
    <force:inputField aura:id="date" value="{!v.newBillable.Date__c}" />
    <label class="slds-form-element__label">Description</label>
    <force:inputField aura:id="desc" value="{!v.newBillable.Description__c}" />
    <lightning:button label="Save Billable" onclick="{!c.handleSaveBillable}" variant="brand" class="slds-m-top-medium"/>
</aura:component>

Here is my Controller:
 
({
    doInit : function (component, event, helper) {
        helper.loadProjects(component);
    },
    
	handleSaveBillable : function(component, event, helper) {
        var newBillable = component.get("v.newBillable");
        helper.upsertBillable(component, newBillable);
    }
})
Helper:
 
({
    loadProjects : function(component) {
        var action = component.get("c.getProjects");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                //component.set("v.projects", response.getReturnValue());
                //var projects = component.get("v.projects");
        		var projects = response.getReturnValue();
                var opts = new Array();
        		opts.push({value: "", label: "- None -"});
                for(var i=0; i<projects.length; i++){
                    var p = projects[i];
                    console.log(p);
                    opts.push({value: p.Id, label: p.Name});
                }
                console.log(opts);
                component.set("v.options", opts);
            } else {
                console.log('Problem getting Projects, response state: '+state);
            }
        });
        $A.enqueueAction(action);
    },
    
    upsertBillable : function(component, billable) {
        var action = component.get("c.saveBillable");
        action.setParams({
            "billable": billable
        });
        $A.enqueueAction(action);
    }
})

Apex Controller:
 
public with sharing class HoursController {
	
    @AuraEnabled
    public static List<Project__c> getProjects(){
        return [SELECT Id, Name FROM Project__c WHERE Status__c = 'Active'];
    }
    
    @auraEnabled
    public static Billable__c saveBillable(Billable__c billable){
        upsert billable;
        return billable;
    }
}

Any help is appreciated.

 
I am attempting to do a call out to an external server to notify it to remove a contact from an opportunity if it is removed from the contact role on the opportunity in Salesforce. However the query I am attempting to use does not return any records. I attempted to delete a contact from an Opportunity and when I check by debug log I see that my query does not ever return any record. I trigger the opportunity successfully when the opportunitycontactrole is edited/deleted but it doesn't return the record. Any suggestion?
 
trigger OCR on Opportunity (after insert, after update, after delete) {

List<OpportunityContactRole> ocr_list_del = [SELECT Id, OpportunityId, ContactId, Role, IsPrimary FROM OpportunityContactRole WHERE OpportunityId IN: Trigger.newmap.keyset() AND IsDeleted=true ALL ROWS];

SYSTEM.DEBUG('The OCR Delete List Size is ' + ocr_list_del.size());

}

 

Hi, I've been sporadically receiving an issue when an OnClick button:

 

"A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'sf:INVALID_SESSION_ID' ...

 

The code is pretty straightforward, it just updates a sigble field in the Case object when clicked:

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';

caseObj.Updated__c = ' ';

var result = sforce.connection.update([caseObj]);
window.location.reload();

Behavior:  Execute JavaScript

Display Type:  Detail Case Button

 

As said, it's sporadic.  Usually the button works fine.  To me it sounds like a timeout on the session, when a user has the case tab open for a while.  I'm sure it could be fixed by refreshing the screen and re-clicking on the button, but I'd prefer a more elegant solution.

 

Any experience with this, insights, thoughts greatly appreciated!

  • August 15, 2012
  • Like
  • 0

The links on this page are broken:

 

http://www.adnsandbox.com/tools/ide/install/

 

The two windows links both give me a file which stops downloading before its full size has come down. A wonderful first impression of the platform for new developers!

 

Cheers,

 

Eliot.

Hi,

 

I need to construct a CSV file with APEX and am a bit new to this cloud computing.

Do you have any sample code I could get started with that, or a resources that you can point me to develop and generate a  CSV File to send through the Email??

 

Can this be achieved in salesforce by any Way?

  • December 29, 2011
  • Like
  • 0

I have a requirement where i need to create a page having many tabs as well as tabPanels. The number of tabs to be displayed is decided at run time. i tried using tabPanel inside repeat but it renders tabPanels again and again but not the tabs. Is there any way to do this using visualforce?

 

for eg: say i have three tabPanels:

 

tabPanel 1 :

 

tab1 tab2 tab3

this contains three tabs(say)

 

tabPanel 2 :

tab 1 tab 2

this contains two tabs(say)

 

etc.

 

again when next time i render the page, tabPanel 1 may have 4 tabs and also the page may have an added, tabPanel with multiple tabs.

 

 

Any Suggestion will be appreciated.

 

Thanks in advance.

  • June 08, 2010
  • Like
  • 0

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions

 

Hi guys,

I'm experiencing some unexpected behavior when trying to use the apex:repeat function to render tabs....

Basically it seems that tabs cannot be created on demand?  My controller is definitely returning data... as the second page block in my sample will show... repeat works - just the tabs are not rendered..

I'm sure any of you guys can see where I was going with this - and I guess I can achieve a similar result by dropping down to boring old html - just trying to use the standard components (as per best practice)

Any assistance greatly appreciated - as the purist coder me is seriously disturbed at the moment...

here is my 'simplified' and easily testable page & controller

Code: VF PAGE
<apex:page controller="clsRecordType">
    <apex:pageBlock >
        <apex:tabPanel id="theTabPanel">
            <apex:tab label="Account Types"/>
            <apex:repeat value="{!RecordTypes}" var="types">
                <apex:tab label="{!types.Name}"/>     
            </apex:repeat>
        </apex:tabPanel>
    </apex:pageBlock>

    <apex:pageBlock >
        <apex:repeat value="{!RecordTypes}" var="types">
            {!types.Name}<br/>       
        </apex:repeat>
    </apex:pageBlock>
</apex:page>

and the controller

Code:
public class clsRecordType {

    list<RecordType> lrecordtypes;

    public list<RecordType> getRecordTypes() {
        if(lrecordtypes==null) lrecordtypes = [Select Name, Id, Description From RecordType  where SobjectType = 'Account' and IsActive=True];
        return lrecordtypes;
        }
   }

 
 

Code:
<apex:page Controller="testController">
<apex:tabPanel switchType="ajax" id="theTabPanel">
<apex:repeat value="{!stringList}" var="astring" id="theRepeat">
<apex:tab label="{!astring}">
</apex:tab>
</apex:repeat>
</apex:tabPanel>
</apex:page>



Code:
public class testController {

String[] ss;
public String[] getStringList() {
return ss;
}

public testController() {
this.ss = new String[]{'a', 'b', 'c'};
}

}


I want to create a variable number of tabs with repeat statement. The code above doesn't work...Any work arounds anyone can think of?