• Jai Chaturvedi
  • NEWBIE
  • 264 Points
  • Member since 2013
  • Salesforce Developer/Consultant

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 68
    Replies
Hi,

I've custom objects and fields. I've created custom settings for these objects and fields. Is there any way to fetch these object's fields into a visualforce page dynamically(Not to hardcode the object name)? 
Please give me some examples as am new to salesforce :)
Hi All,

I am trying to create a custom button ("LVM") on the lead object that will create a task, applied the current date and sets the status to complete.

Here's what I have so far:

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

var t1= new sforce.SObject("Task"); 
t1.Subject = "LVM";
t1.Status = "Completed"; 
t1.Priority = "Normal"; 
t1.OwnerId = "{!User.Id}";
t1.ActivityDate =  new Date();
 
result = sforce.connection.create([t1]);

  if(result[0].success=='true'){
      alert('Your Left voice mail (LVM) task has been created.');
      location.reload();
  }
else
{
alert(result[0]);
}

This currently delivers the alert but does not create the task.

Origionally we used the following:
 
t1.WhatId = "{!Lead.Id}"; 

But received and error message upon pressing the button.

Any help would be much appreciated!

Thanks,

Anthony
I have got two batch classes written for Integrating from SF to ActiveCampaign and need to execute one after the other.
May I know how to do it?
Hi Guys...

I am new to salesforce and also not an employee of any salesforce firm but I would like to take certification in salesforce.Could you suggest me some solutions.Please help me out

with Thanks and regards

Hello Community, 

Having an issue with a Bulk Apex Trigger challenge here, hope you guys can assist. 

Here is the critieria:
To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.

Here is the Error Received:
Challenge not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Discount_Percent__c]: [Discount_Percent__c]

Here Is My Code:

trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
 
    List<Task> taskList = new List<Task>();
         
    for(Opportunity opp : Trigger.new) {
         
        //Only create Follow Up Task only once when Opp StageName is to 'Closed Won' on Create
        if(Trigger.isInsert) {
            if(Opp.StageName == 'Closed Won') {
                taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
                }
            }
             
            //Only create Follow Up Task only once when Opp StageName changed to 'Closed Won' on Update
            if(Trigger.isUpdate) {
                if(Opp.StageName == 'Closed Won'
                && Opp.StageName != Trigger.oldMap.get(opp.Id).StageName) {
                    taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
                }
        }      
    }
     
        if(taskList.size()>0) {       
            insert taskList;       
    }   
}


Please Note: I appended the code from SumitKumar from another post which worked for others as I changed my code to suit the suggested code.above. It seems I may have an insert dml exception issue maybe caused by an earlier code insertion. PLEASE ADVISE

Hi,

I am trying to open a hyperlink on my account record. I have field website on Account. I have created a button which will open the website.
i treid with URL but its adds the salesforce url and than addes the website

Could any one provide me the sloution.

Thanks
ShaT
  • September 05, 2014
  • Like
  • 0
I have written code to access camera from VF page. It is working fine in laptop browser and mobile browser. But when I am trying the same VF page in Salesforce1 app it is not accessing camera.I am using Andriod OS.

I tried 2 approaches, both are not working.

Approach 1: Using <apex:inputFile accept="image/*;capture=camera" />
Page:
<apex:page controller="CameraAccess2" standardStylesheets="false" showHeader="false" docType="html-5.0">
    <apex:form >
        Enter File Description
        <p>
            <apex:inputText value="{!AttachmentName}" />
            <apex:inputFile value="{!attachmentObj.Body}"  accept="image/*;capture=camera" />
        </p>
        <p>
            <apex:commandButton  action="{!saveFile}" value="Save File" />
        </p>
    </apex:form>
</apex:page>
 
public class CameraAccess{
    public Attachment attachmentObj {get;set;}
    public String AttachmentName {get;set;}
    public CameraAccess() {
        attachmentObj = new Attachment();
    }     

    public PageReference saveFile()
    {
        attachmentObj.ParentId = '003J000000wGwBR';
        attachmentObj.Name = AttachmentName +'.jpg';
        insert attachmentObj;
        return new PageReference('/003J000000wGwBR');
    }
}

Approach 2: Using Javascript WebCam api.​
 
<apex:page sidebar="false" showHeader="false" standardStylesheets="false">
<apex:includeScript value="{!URLFOR($Resource.jQueryPackageReport, 'package/media/js/jquery-1.11.1.min.js')}"/>

<title>Webcam</title>
<div  style="background-color:#FFF">
    <div  style="padding-top: 2%;padding-bottom: 1%;">
        <div class="col-md-2 col-md-offset-3" >
            <button class="btn btn-primary" style="margin-top:10px" id="snap" >Capture</button>
            <button class="btn btn-primary" style="margin-top:10px;display:none" id="new">Retake</button>    
            <button class="btn btn-primary" style="margin-top:10px;display:none" id="upload">Upload</button>
        </div>


        <div >
            <select class="form-control" style="margin-top:10px" id="videoSource"></select>
        </div>

    </div>
    <div style="padding-top: 2%;padding-bottom: 1%;" >
        <div align="center">
            <canvas id="canvas" style="display:none;border-radius: 15px;" width="240" height="200"></canvas>
            <video class="myvideo" id="video" autoplay="autoplay" style="border-radius: 15px;"></video> 
        </div>
    </div> 

    <div id="el_loading" style="display:none;position: fixed;top:0;background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
        <div  style="top: 50%; width: 91px;  margin: 20% 47%;"> 
            <img  src="/img/loading.gif" title="Please Wait..."/>
            <span>Saving...</span>
        </div>
    </div>  
</div>

<div  id="myModal1">
    <div style="padding-top: 5%">  
        <div style="background-color: #2AD67B;color: white;border-radius: 7%;">
            <div  style="background-color: #2AD67B;color: white;border-radius: 7%;">
                <button class="close" onclick="hideTheBoxComponent();" style="color:white" type="button">&times;</button>
                <p style="margin-left: 39%;font-size: large;margin-top: 4%;">
                     Image Saved
                </p>
            </div>
        </div>
    </div>
</div>



<script>   
    function hideTheBoxComponent(){
        $("#myModal1").modal('hide'); 
    }

    function showDialogComponent(){
        $("#myModal1").modal({
          "backdrop"  : "static",
          "keyboard"  : true,
          "show"      : true 
        });
    }

    // Put event listeners into place
    window.addEventListener("DOMContentLoaded", function() {

        // Grab elements, create settings, etc.
        var canvas = document.getElementById("canvas"),
            context = canvas.getContext("2d"),
            video = document.getElementById("video"),
            videoObj = { "video": true },
            errBack = function(error) {
                console.log("Video capture error: ", error.code); 
            };

        // Capture Snap Photo
        document.getElementById("snap").addEventListener("click", function() {
            context.drawImage(video, 0, 0, 250, 200);
            // Littel effects
            $('#video').hide();
            $('#canvas').show();
            $('#snap').hide();
            $('#new').show();
            $('#upload').show();
        });

        // Capture New Photo
        document.getElementById("new").addEventListener("click", function() {
            $('#video').show();
            $('#canvas').hide();
            $('#snap').show();
            $('#new').hide();
            $('#upload').hide();
        });



    }, false);

    'use strict';

    var videoElement = document.querySelector('video');    
    var videoSelect = document.querySelector('select#videoSource');
    navigator.getUserMedia = navigator.getUserMedia ||
      navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

    function gotSources(sourceInfos) {
      for (var i = 0; i !== sourceInfos.length; ++i) {
        var sourceInfo = sourceInfos[i];
        var option = document.createElement('option');
        option.value = sourceInfo.id;
        if (sourceInfo.kind === 'video') {
          option.text = sourceInfo.label || 'camera ' + (videoSelect.length + 1);
          videoSelect.appendChild(option);
        } else {
          console.log('Some other kind of source: ', sourceInfo);
        }
      }
    }

    if (typeof MediaStreamTrack === 'undefined'){
      alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
    } else {
      MediaStreamTrack.getSources(gotSources);
    }

    function successCallback(stream) {
      window.stream = stream; // make stream available to console
      videoElement.src = window.URL.createObjectURL(stream);
      videoElement.play();
    }

    function errorCallback(error){
      console.log('navigator.getUserMedia error: ', error);
    }

    function start(){
      if (!!window.stream) {
        videoElement.src = null;
        window.stream.stop();
      }
      var videoSource = videoSelect.value;
      var constraints = {

        video: {
          optional: [{sourceId: videoSource}]
        }
      };
      navigator.getUserMedia(constraints, successCallback, errorCallback);
    }
    videoSelect.onchange = start;
    start();
</script>
</apex:page>

Both are not wokring. Please help. If there is any other way then please share.

I want user to take snapshot from camera and save it on object.
I have written code to access camera from VF page. It is working fine in laptop browser and mobile browser. But when I am trying the same VF page in Salesforce1 app it is not accessing camera.I am using Andriod OS.

I tried 2 approaches, both are not working.

Approach 1: Using <apex:inputFile accept="image/*;capture=camera" />
Page:​
<apex:page controller="CameraAccess2" standardStylesheets="false" showHeader="false" docType="html-5.0">
    <apex:form >
        Enter File Description
        <p>
            <apex:inputText value="{!AttachmentName}" />
            <apex:inputFile value="{!attachmentObj.Body}"  accept="image/*;capture=camera" />
        </p>
        <p>
            <apex:commandButton  action="{!saveFile}" value="Save File" />
        </p>
    </apex:form>
</apex:page>
 
public class CameraAccess{
    public Attachment attachmentObj {get;set;}
    public String AttachmentName {get;set;}
    public CameraAccess() {
        attachmentObj = new Attachment();
    }     

    public PageReference saveFile()
    {
        attachmentObj.ParentId = '003J000000wGwBR';
        attachmentObj.Name = AttachmentName +'.jpg';
        insert attachmentObj;
        return new PageReference('/003J000000wGwBR');
    }
}

Approach 2: Using Javascript WebCam api
 
<apex:page sidebar="false" showHeader="false" standardStylesheets="false">
<apex:includeScript value="{!URLFOR($Resource.jQueryPackageReport, 'package/media/js/jquery-1.11.1.min.js')}"/>

<title>Webcam</title>
<div  style="background-color:#FFF">
    <div  style="padding-top: 2%;padding-bottom: 1%;">
        <div class="col-md-2 col-md-offset-3" >
            <button class="btn btn-primary" style="margin-top:10px" id="snap" >Capture</button>
            <button class="btn btn-primary" style="margin-top:10px;display:none" id="new">Retake</button>    
            <button class="btn btn-primary" style="margin-top:10px;display:none" id="upload">Upload</button>
        </div>


        <div >
            <select class="form-control" style="margin-top:10px" id="videoSource"></select>
        </div>

    </div>
    <div style="padding-top: 2%;padding-bottom: 1%;" >
        <div align="center">
            <canvas id="canvas" style="display:none;border-radius: 15px;" width="240" height="200"></canvas>
            <video class="myvideo" id="video" autoplay="autoplay" style="border-radius: 15px;"></video> 
        </div>
    </div> 

    <div id="el_loading" style="display:none;position: fixed;top:0;background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
        <div  style="top: 50%; width: 91px;  margin: 20% 47%;"> 
            <img  src="/img/loading.gif" title="Please Wait..."/>
            <span>Saving...</span>
        </div>
    </div>  
</div>

<div  id="myModal1">
    <div style="padding-top: 5%">  
        <div style="background-color: #2AD67B;color: white;border-radius: 7%;">
            <div  style="background-color: #2AD67B;color: white;border-radius: 7%;">
                <button class="close" onclick="hideTheBoxComponent();" style="color:white" type="button">&times;</button>
                <p style="margin-left: 39%;font-size: large;margin-top: 4%;">
                     Image Saved
                </p>
            </div>
        </div>
    </div>
</div>



<script>   
    function hideTheBoxComponent(){
        $("#myModal1").modal('hide'); 
    }

    function showDialogComponent(){
        $("#myModal1").modal({
          "backdrop"  : "static",
          "keyboard"  : true,
          "show"      : true 
        });
    }

    // Put event listeners into place
    window.addEventListener("DOMContentLoaded", function() {

        // Grab elements, create settings, etc.
        var canvas = document.getElementById("canvas"),
            context = canvas.getContext("2d"),
            video = document.getElementById("video"),
            videoObj = { "video": true },
            errBack = function(error) {
                console.log("Video capture error: ", error.code); 
            };

        // Capture Snap Photo
        document.getElementById("snap").addEventListener("click", function() {
            context.drawImage(video, 0, 0, 250, 200);
            // Littel effects
            $('#video').hide();
            $('#canvas').show();
            $('#snap').hide();
            $('#new').show();
            $('#upload').show();
        });

        // Capture New Photo
        document.getElementById("new").addEventListener("click", function() {
            $('#video').show();
            $('#canvas').hide();
            $('#snap').show();
            $('#new').hide();
            $('#upload').hide();
        });



    }, false);

    'use strict';

    var videoElement = document.querySelector('video');    
    var videoSelect = document.querySelector('select#videoSource');
    navigator.getUserMedia = navigator.getUserMedia ||
      navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

    function gotSources(sourceInfos) {
      for (var i = 0; i !== sourceInfos.length; ++i) {
        var sourceInfo = sourceInfos[i];
        var option = document.createElement('option');
        option.value = sourceInfo.id;
        if (sourceInfo.kind === 'video') {
          option.text = sourceInfo.label || 'camera ' + (videoSelect.length + 1);
          videoSelect.appendChild(option);
        } else {
          console.log('Some other kind of source: ', sourceInfo);
        }
      }
    }

    if (typeof MediaStreamTrack === 'undefined'){
      alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
    } else {
      MediaStreamTrack.getSources(gotSources);
    }

    function successCallback(stream) {
      window.stream = stream; // make stream available to console
      videoElement.src = window.URL.createObjectURL(stream);
      videoElement.play();
    }

    function errorCallback(error){
      console.log('navigator.getUserMedia error: ', error);
    }

    function start(){
      if (!!window.stream) {
        videoElement.src = null;
        window.stream.stop();
      }
      var videoSource = videoSelect.value;
      var constraints = {

        video: {
          optional: [{sourceId: videoSource}]
        }
      };
      navigator.getUserMedia(constraints, successCallback, errorCallback);
    }
    videoSelect.onchange = start;
    start();
</script>
</apex:page>

Both are not wokring. Please help. If there is any other way then please share.

I want user to take snapshot from camera and save it on object.
I am working on Lightning Builder but when trying to create there are no standard or custom components are visible to select from, does anyone knows whats the reason for this?
I have enable the domain and deployed to users, which is required for working on lightning. Also, I created a new dev org and there also the same thing is happeing.

 
Hi All,

I am getting the error When i try to fire a event wit following code 
gotoURL : function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": "/006/o"
    });
    urlEvent.fire();
}

 
Hello All,

I tried out the Lightning App Builder and it worked, later on I developed Lightning components on my own in the developer console, and at some point in time there were no available components in the Lightning App Builder (see screenshot).
User-added image
Does somebody know what the problem could be?

Thanks in advance.

Best regards
Andrey
I want to display cases related to loggedin user account. It is displaying empty list(it is not returning any values). When tried in query editor the query is working I am not understanding where i am making mistake can anyone pls help me with this ?
here is my code:
Controller:
public class CaseInformation{

        @AuraEnabled
        public static List<Case> getCases() {

        ID contactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
        if(contactId == null)
        {
            return NULL;            
        }
        ID AccID  = [Select AccountID from Contact where id =: contactid ].AccountId;
            if(AccID == null){
                return NULL;
            }
            System.debug('AccountId :' + AccID + 'ContactId:' + contactId);
            List<Account> allAssocaiatedAccounts = [Select Id, name, industry from Account where Id =: AccID];
            if(allAssocaiatedAccounts.size() != 0){
            return [Select CaseNumber,Status,Priority,Type,Subject,AccountID from Case where AccountID IN: allAssocaiatedAccounts];
            }
            else {
                return NULL;
            }
    }  

}
Lightning Component:
 
<aura:component controller="CaseInformation">
<aura:attribute name="caseRows" type="Object[]"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:iteration var="cas" items="{!v.caseRows.Cases}">
                    <tr class="border_bottom">
                        <td > {!cas.CaseNumber} </td>
                        <td > {!cas.Subject}  </td>
                        <td >{!cas.Status}</td>
                        <td> <ui:outputDate format="MMM dd yyyy" value="{!cas.CreatedDate}"/> </td>
                        <td >{!cas.Account.Name}</td>
                    </tr><hr class="hrcolclass" />
                </aura:iteration>
</aura:component>

Component Controller:
 
({
    doInit : function(component, event, helper){
        helper.getAllCases(component);
     }
})
Helper:
({
    getAllCases : function(component, event, helper) {
        var action = component.get("c.getCases");

        action.setCallback(this, function(a){
            component.set("v.caseRows", a.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})



 
I am trying to create a lightning component which displays an Account Record and two other text fields. The data from UI is used to create a record in  separate custom object. 
How to implement this?
 
HI,
I have a requirement to create a new Event from a custom lightning component. the code i used is below

<aura:component >
 <aura:attribute name="newEvent" type="Event"
                    default="{ 'sobjectType': 'Event',
                             'Subject':'',
                             'Description':''
                             }"/>
<div>
<ui:inputText aura:id="subject" class="slds-input" value="{!v.newEvent.Subject}"
                                                      placeholder="Enter Subject"/>
<ui:inputTextArea aura:id="comment" class="slds-input" value="{!v.newEvent.Description}" 
                                                          placeholder="provide your comments"/>
<button class="slds-button slds-button--neutral" onclick="{!c.cancel}">Cancel</button>
<button class="slds-button slds-button--neutral slds-button--brand" onclick="{!c.save}">Save</button>
</div>
</aura:component>

---controller----
({
    save : function(component) {
        var event = component.get("v.newEvent");
        window.alert(event);        //getting undefined
}
})

I am getting values as undefined. In case if I use sObject as Task instead of an Event, this is working Good and values passed are getting displayed. Is this due to the confusion between lightning events and sObject Event or anything ? Any help here is very much appreciated.
Thank You!
With a Visualforce community I can edit the code e.g. CommunitiesLogin.vfp and CommunitiesLoginController.cls. Can I do this with a Lightning templated community too?

In a Napili community I have edited loginform.cmp and other Lightning resources but so far my edits haven't been reflected in the community. Are these components even being used by it?
 I am trying to fire a trigger on object ‘Router_custom_object__c' when either ‘In_service__c’ || ‘Channel_designation_del__c' || ‘Router_designation' have been updated or new object is created.
IF the fields are updated or new object is created, then I compare the 3 fields of 'Router_custom_object__c '(concatenated together) with field ‘all_fields' of custom object ‘TRU_Groups__c' 
and if they match then 
 Router_custom_object__c. TRU_c = TRU_Groups__c .Name
This is how my values of field ‘all_fields__c' looks like:
 No, Aftermarket, Subscriber
My code:
Trigger TruFieldUpdate on Router_custom_object__c (before insert, before update) {
  Map<Id, Router_custom_object__c> changedRouters = new Map<Id, Router_custom_object__c>();
  Map<Id, String> afTargets = new Map<Id, String>(); // Map of Router->All_field__c 
    
    // Build a list of routers whose groups MAY have changed
    if(trigger.isInsert) {
        // All new routers
        for(Router_custom_object__c newR: trigger.new) {
            changedRouters.put(newR.Id, newR);
        }
    } else {
        // Some updated routers, if the relevant fields have been updated
        for(Router_custom_object__c oldR: trigger.old) {
            Router_custom_object__c newR = trigger.newMap.get(oldR.Id);
            if( (oldR.In_service__c != newR.In_service__c) || (oldR.Channel_designation_del__c != newR.Channel_designation_del__c) || (oldR.Router_designation__c != newR.Router_designation__c) ) {
                changedRouters.put(newR.Id, newR);
            }
        }
    }
    
    // The string we're building here matches the computation done for TRU_Groups__c.all_fields__c
    // Map this computer field to router Id.
    for(Router_custom_object__c oneR: changedRouters.values()) {
        afTargets.put(oneR.Id, oneR.In_service__c+','+oneR.Channel_designation_del__c+','+oneR.Router_designation__c);
    }
    
    // Get all the group records matching our afTargets values.
    List<TRU_Groups__c> foundGroups = [select Name, all_fields__c from TRU_Groups__c where all_fields__c in :afTargets.values()];
    
    // For each router in afTargets, find the new Group value
    for(Id rId: afTargets.keySet()) {
        String routerFields = afTargets.get(rId);
        for(TRU_Groups__c oneG: foundGroups) {
            if(oneG.all_fields__c == routerFields) {
                // finally, change the router record.
                Router_custom_object__c r = changedRouters.get(rId);
                r.TRU__c = oneG.Name;
                break;
            }
        }
    }
    
}

 
Hi,

I've custom objects and fields. I've created custom settings for these objects and fields. Is there any way to fetch these object's fields into a visualforce page dynamically(Not to hardcode the object name)? 
Please give me some examples as am new to salesforce :)
Hello,

I have a below screenshot which gives erro for trigger.
I have system admin for this org, but i am not able to find this pag layout or correspinding fields in activities.

User-added image
  • August 21, 2015
  • Like
  • 0
Hi All,

I am trying to create a custom button ("LVM") on the lead object that will create a task, applied the current date and sets the status to complete.

Here's what I have so far:

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

var t1= new sforce.SObject("Task"); 
t1.Subject = "LVM";
t1.Status = "Completed"; 
t1.Priority = "Normal"; 
t1.OwnerId = "{!User.Id}";
t1.ActivityDate =  new Date();
 
result = sforce.connection.create([t1]);

  if(result[0].success=='true'){
      alert('Your Left voice mail (LVM) task has been created.');
      location.reload();
  }
else
{
alert(result[0]);
}

This currently delivers the alert but does not create the task.

Origionally we used the following:
 
t1.WhatId = "{!Lead.Id}"; 

But received and error message upon pressing the button.

Any help would be much appreciated!

Thanks,

Anthony
I have the code below as a button in a VF page.  When clicked, a new tab opens up with the same page.  How can I prevent a new tab from being opened in the browser and just refresh the page where the user clicked the button?  I tried adding "_parent" and "_self" to the onclick code, but it didn't do anything.  Thanks.
 
<button
            class="btn" 
            style="background:#99C299; height:35px; width:250px;"
            onclick="javascript:window.open('/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}');">
            <b>Submit For Approval</b>
            </button>