• Sandeep Yadav
  • NEWBIE
  • 94 Points
  • Member since 2017
  • Salesforce Developer


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 9
    Questions
  • 40
    Replies
Apex class
-------------
public class StringStack {

      private List<String> stack;

    public StringStack()
    {
         stack = new List<String>();

    }

    public void push(String s)
    { 
        stack.add(s); 
    }
    public String pop() 
    {
       
    return stack.remove( lastItemIndex );
    }
    public String peak() 
    {

        return stack.get( lastItemIndex );

    }

 
    public Boolean isEmpty() 
    { 
        return stack.isEmpty();
    }
     

    // Helper Property

    private Integer lastItemIndex
    {
        get 
        { 
            return stack.size() - 1;
            }
    }

}



Test clas
------------
@isTest
public class TestStringStack 
 {
public static testmethod void StringStackcheck()
{
    //Instantiate a StringStack.

    StringStack stack = new StringStack();
 // Set up some test data.

    String bottomString = 'Bottom String';
    String middleString = 'Middle String';
    String topString = 'Top String';

      // Call the push() method with multiple objects

    stack.push(bottomString);

    stack.push(middleString);
    stack.push(topString);

    // Verify that the 'top' object is the object we expected

    String peakValue = stack.peak();

    System.assertEquals(topString, peakValue);

    // Verify that the order of the objects is as we expected
    String popValue = stack.pop();
    System.assertEquals(topString, popValue);
    popValue = stack.pop();
    System.assertEquals(middleString, popValue);
    popValue = stack.pop();
    System.assertEquals(bottomString, popValue);
    System.assert(stack.isEmpty());

}
 }
Hello everyone,
Is API integration is required to get any company's tweets in a sObject ??
For example i want to store google tweets in a object.

Any help regarding this ??

Regards
Sandeep
Here is what i have done.
By clicking on edit button am calling editActionHelper from JS Controller....
editActionHelper : function(component,event,helper){
        var buttonValue = event.getSource().get('v.value');
        var editRecordEvnt = $A.get('e.force:editRecord');
        editRecordEvnt.setParams({
            recordId : buttonValue
        });
        editRecordEvnt.fire();
        $A.get('e.force:refreshView').fire();
    },
Any help regarding this???
 
Hi All,

I have use a SVG icon for a button that is displaying in Chrome and Firefox but not displaying in IE 11.
I use this code as given in SLDS library.
<button class="slds-button slds-button_icon" title="Add New Competition" name="data" type="button" onclick="addCompetitionAF()">
    <svg class="slds-button__icon" aria-hidden="true">
        <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#add')}"></use>
    </svg>
    <span class="slds-assistive-text">Add New Competition</span>
</button>
Please,suggest any correction what i need to add diffrent script to shown these images as a button in IE11.
Regards
Sandeep
 
Hi everyone,
I am calling this method from test class and it is not covering the statements inside if condition.
what's going wrong!!
Any help would be appreciate.User-added image
Hi everyone,
Here is my code--
when I debug it shows null value.
Any suggestion ??
<apex:page controller="AlertConId" >
  
  <script type="text/javascript">
      
      function demo(fst,lst)
      {
          var fn = document.getElementById(fst).value;
          var ln = document.getElementById(lst).value;
          myFunction(fn,ln);
      }
  </script>
  
  <apex:form >
      <apex:actionFunction name="myFunction" action="{!save}">
          <apex:param value="" name="fname" assignTo="{!fname}"/>
          <apex:param value="" name="lname" assignTo="{!lname}"/>
      </apex:actionFunction>
      
      <apex:pageBlock id="ref">
          <apex:pageBlockSection >
              <apex:inputText id="fname" label="FirstName"/>
              <apex:inputText id="lname" label="LastName"/>
              
              <apex:commandButton value="Go" onclick="demo('{!$Component.fname}','{!$Component.lname}')" reRender="ref"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

------------------------------------------------------------------------------------------------------------

public class AlertConId 
{
    public Contact ct {get;set;}
    public string fname {get;set;}
    public string lname {get;set;}
    
    public void save()
    {
        string first = ApexPages.currentPage().getParameters().get('fname');
        string last = ApexPages.currentPage().getParameters().get('lname');
        system.debug(first + last);
        
        ct = new Contact();
        ct.firstname = first;
        ct.lastname = last;
        try{
            insert ct;
        }
         catch(Exception e){}
    }
}

 
Hello everyone,
I want to upload a number of files when I select a value in the picklist.i.e. when I select 2 in picklist then it uploads only two files and so on.
Here is the code what I did to achieve this.
Thanks in advance
VF Page--

<apex:page standardController="Document" extensions="MyDocuments">
  <apex:form >
      <apex:pageBlock >          
          <apex:selectList value="{!len}" size="1">
              <apex:selectOptions value="{!option}"/>
              <apex:actionSupport event="onchange" action="{!uploadMultiFile}" reRender="lab"/>
          </apex:selectList>
      </apex:pageBlock>
      
      <apex:pageBlock title="UpLoad A File">
          <apex:pageBlockSection id="lab">
              <apex:repeat value="{!total}" var="t">
                  <apex:inputFile value="{!doc.body}" fileName="{!doc.name}"/>
              </apex:repeat>
              <apex:commandButton value="Save" action="{!save}"/>

          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

---------------------------------------------------------------------------------------------------------------------
Controller--

public class MyDocuments {
    
    public document doc {get;set;}
    public List<selectOption> option {get;set;}
    public String len {get;set;}
    public Integer total {get;set;}
    
    
    public MyDocuments(ApexPages.StandardController controller) 
    {
        doc = (Document)controller.getRecord();
        doc.folderId = UserInfo.getUserId();
        
        option = new List<selectOption>();
        option.add(new selectOption('','--None--'));
        for(Integer i=1; i<=10; i++)
        {
            option.add(new selectOption('val'+i,string.valueOf(i)));
        }
        
    }
    
    public void uploadMultiFile()
    {
        if(len == 'val1')
        {
            total = 1;
        }
        if(len == 'val2')
        {
            total = 2;
        }
    }

}

 
Am, using the concept of Wrapper class. I want to delete recently created contact record from pageBlockTable.
I am facing Unknown property 'SingleRecordDelete.ContactWrp.id' Error
Here is What I did--

VF page

<apex:page controller="SingleRecordDelete">
  <apex:form >
     <apex:pageBlock title="Contacts">
          <apex:pageBlockSection title="New Contact" columns="2" id="fresh">
              <apex:inputText label="FirstName" value="{!fname}" />
              <apex:inputText label="LastName" value="{!lname}"/>
              <apex:commandButton action="{!save}" value="Save" reRender="lab,fresh"/>
          </apex:pageBlockSection> 
         
          <apex:pageBlockSection title="ContactList" id="lab">
              <apex:pageBlockTable value="{!crp}" var="cy" id="update">
                  <apex:column headerValue="FirstName">
                      <apex:outputLabel value="{!cy.cn.firstname}"/>
                  </apex:column>
                  <apex:column headerValue="LastName">
                      <apex:outputLabel value="{!cy.cn.lastname}"/>
                  </apex:column>
                  <apex:column >
                         <apex:commandLink value="Delete" action="{!doDelete}" style="color:Red" reRender="lab">
                             <apex:param name="did" value="{!cy.id}" assignTo="{!did}"/>
                         </apex:commandLink>
                  </apex:column>
                  
              </apex:pageBlockTable>
                  
          </apex:pageBlockSection> 
               
     </apex:pageBlock>
  </apex:form>
</apex:page>

ApexClass
public with sharing class SingleRecordDelete {

    public String fname {get;set;}
    public String lname {get;set;}
    public String did {get;set;}
    
    public List<ContactWrp> crp {get;set;}
    
    public SingleRecordDelete(){
        crp = new List<ContactWrp>();
        
    }
    
    public void save(){
      Contact c = new Contact();
      c.firstname = fname;
      c.lastname = lname;
      insert c;
      crp.add(new ContactWrp(c));
      fname='';
      lname='';
    }
    
    public void doDelete()
    {
        List<Contact> contactToBeDelete = new List<Contact>();
        Contact cod = [select id from Contact where id =: did];
        contactToBeDelete.add(cod);
        delete contactToBeDelete;
    }
    
     public class ContactWrp{
    
      public Contact cn {get;set;}
      
        public ContactWrp(Contact cs){
            this.cn = cs;                   
        }
    }
}
On execution this in my Anonymous window --

List<List<sObject>> searchList = [FINd 'Mission Control' in ALL Field
                                   RETURNING Contact(FirstName,LastName,Email,Phone,Department)];

 Contact[] searchContacts = (Contact[])searchList[0];
    System.debug(searchContacts[0].LastName + ' ,' + searchContacts[0].FirstName);

a PopBox says that-
Unexpected Token at Line 1

 
Why I am getting this error--
"Executing the 'insertNewAccount' method failed. Either the method does not exist, is not static, or does not insert the proper account."
my code--

public class AccountHandler {

     public static Account insertNewAccount(String name){
        
          Account a = new Account();
          a.Name = 'name';
        
        try{
            insert a;
        }
        catch(Exception e){
            return null;
        }    
       return a;
    }
}
Here is what i have done.
By clicking on edit button am calling editActionHelper from JS Controller....
editActionHelper : function(component,event,helper){
        var buttonValue = event.getSource().get('v.value');
        var editRecordEvnt = $A.get('e.force:editRecord');
        editRecordEvnt.setParams({
            recordId : buttonValue
        });
        editRecordEvnt.fire();
        $A.get('e.force:refreshView').fire();
    },
Any help regarding this???
 
Hi All,

I have use a SVG icon for a button that is displaying in Chrome and Firefox but not displaying in IE 11.
I use this code as given in SLDS library.
<button class="slds-button slds-button_icon" title="Add New Competition" name="data" type="button" onclick="addCompetitionAF()">
    <svg class="slds-button__icon" aria-hidden="true">
        <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#add')}"></use>
    </svg>
    <span class="slds-assistive-text">Add New Competition</span>
</button>
Please,suggest any correction what i need to add diffrent script to shown these images as a button in IE11.
Regards
Sandeep
 
i want to know how many times the execute method will run , so it is poossible to know using finish method.i mean after execute the batch class ,finnally i want see how many times my execute method will run. please give me simple example
Hi Team,

How can we write the test class for below class.
public with sharing class ControllerCls {
      
    public Contact co{get;set;}
    
    private final Contact con;
    
    private ApexPages.StandardController sc{get;set;}
    
    public Opportunity opp = new Opportunity();
    
    public ControllerCls(ApexPages.StandardController sc){
        this.sc = sc;
        con = (Contact)sc.getRecord();
        
        if(con.Name__c != Null){
            opp =[select id,name,AccountId from Opportunity where id =: con.Name__c limit 1];
        }
            
        co = new Contact();
        
        co.AccountId = opp.AccountId;
      
    }
    
    public PageReference save(){
        try{
            Database.insert(con);
            PageReference pr = new PageReference('/'+con.Id);
       		pr.setRedirect(true);
            return pr;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
            return null;
        }        
    }
    
    public PageReference saveNew()
     { 
         PageReference pr; 
         try{
             Database.insert(con);
         Schema.DescribeSObjectResult describeResult = sc.getRecord().getSObjectType().getDescribe();
         pr = new PageReference('/' + describeResult.getKeyPrefix() + '/e');
         pr.setRedirect(true);
         return pr;
         }catch(Exception e){ 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
         return null; }
     
     }
    
}
Please let me know how can we cover 100% code coverage.

Thanks,
sfdc dev.
 
  • September 18, 2018
  • Like
  • 0
    Hi All,
    my helper class is given below-
 //Helper class for Trigger_SocialPost
public without sharing class SocialPostTriggerHelper {
    public static List<SocialPost> newList;
    public static List<SocialPost> oldList;
    public static Map<Id, SocialPost> newMap;
    public static Map<Id, SocialPost> oldMap;
    
    public static Boolean runTrigger = true;
    
    public static void parseImageResponse(){
        Set<Id> socialPostIds = new Set<Id>(newMap.keySet());
        List<contentdocumentlink> cdlList = new List<contentdocumentlink>([Select id, 
                                                                              LinkedEntityId 
                                                                              from contentdocumentlink 
                                                                              where LinkedEntityId IN: socialPostIds]);
        List<Predictions__c> pdcList = new List<Predictions__c>();
        for(contentdocumentlink cdl : cdlList){
            if(newMap.containsKey(cdl.LinkedEntityId)){
               String jsonResponse = EinsteenPredictionService.getImagePrediction('test');
               EinsteenPredictionService ep= EinsteenPredictionService.parseImagePrediction(jsonResponse);
                for(EinsteenPredictionService.cls_probabilities result: ep.probabilities) {
                    Predictions__c    pc = new Predictions__c();
                    pc.Label__c = result.label;
                    pc.Probability__c = result.probability;
                    pc.ReferencetoSocialPost__c = cdl.LinkedEntityId;
                    pdcList.add(pc);
                }
               
            }
        }
        if(pdcList.size() > 0){
           insert pdcList; 
        }
        
    }
}
my test class is given below:-
@isTest
public class SocialPostTriggerHelperTest {
     @isTest static void SocialPostTriggerHelperTestmethod(){
        SocialPostTriggerHelper sth = new SocialPostTriggerHelper();
        SocialPostTriggerHelper.parseImageResponse();
        SocialPost sp = new SocialPost();
         
         Map<Id, SocialPost> newMap = new Map <Id, SocialPost>();
         newMap.put(sp.id,sp);
         insert sp;
         EinsteenPredictionService.cls_probabilities ein = new EinsteenPredictionService.cls_probabilities();
         ein.label = 'nachos';
         ein.probability = 0.9994034;
         
         contentdocumentlink cdl = new contentdocumentlink();
         
                    Predictions__c pc = new Predictions__c();
                    pc.Label__c = ein.label;
                    pc.Probability__c = ein.probability;
                    pc.ReferencetoSocialPost__c = cdl.LinkedEntityId;
         test.startTest();
         insert pc;
         test.stopTest();
     }
}
its showing this error:-System.NullPointerException: Attempt to de-reference a null object
                        Class.SocialPostTriggerHelper.parseImageResponse: line 11, column 1
                        Class.SocialPostTriggerHelperTest.SocialPostTriggerHelperTestmethod: line 5, column
     how to solve this error and cover the code?
Any suggestion?
Hello,

How can i calculate time between last modified date and present modified date and get the time in minutes.
where can i store t, in number field or text field.

thank for suggestion
Hi,

I am new in lightning. I am making one module in lightning, which have 4 or 5 buttons to do different activities. Should I create different component for each button or developments in the same (Base) component.


Thanks & Regards,
Kanahaiya
Hi everyone,
I am calling this method from test class and it is not covering the statements inside if condition.
what's going wrong!!
Any help would be appreciate.User-added image
Hi devs!
I'm having a problem when assigning a value into a custom field in a custom object. The error message is the following:
Line: 6, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST
Some important points:
  • I need it to be restricted.
  • This field doesn't use a global value set.
  • There's no record types defined for this object.
  • The value I'm trying to set are in the value set, and I already checked for typos.
  • If I unmark the "Restrick picklist to values..." option, the record saves, but an identical value is added to the picklist. 
  • I use the API value for the assignation, but I've tried with Label too.
  • The user can set the value trhough User Interface correctly
What could be happening here? 
Regards,
Mario Bravo
I tried a simpe code to display a list of contacts in vfpage
public class Payment {
public List<Contact> ls{get;set;}
public Set<String> st{get;set;}
public string str{get;set;}


    public Payment(){
    List<Contact> ls = new List<Contact>();
    ls = [select id, name from contact limit 3];
    Set<String> st = new Set<String>();
    st.add('1111111');
    st.add('addad');
    st.add('gxghdy');
    st.add('6366vx');
    str = '123';
    
    }
}

<apex:page controller="Payment">
    {!ls}{!st}{!str}
    <apex:pageBlock >
        <apex:pageBlockTable value="{!ls}" var="a">
            <apex:column value="{!a.name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
User-added image
checked all sharing settings every thing is public
this is my new dev edition signedup today
i had same issue with one signed up this month
is this a bug or an issue with my code

--- I can see contacts in debug logs
 
  • March 10, 2018
  • Like
  • 0
Apex class
-------------
public class StringStack {

      private List<String> stack;

    public StringStack()
    {
         stack = new List<String>();

    }

    public void push(String s)
    { 
        stack.add(s); 
    }
    public String pop() 
    {
       
    return stack.remove( lastItemIndex );
    }
    public String peak() 
    {

        return stack.get( lastItemIndex );

    }

 
    public Boolean isEmpty() 
    { 
        return stack.isEmpty();
    }
     

    // Helper Property

    private Integer lastItemIndex
    {
        get 
        { 
            return stack.size() - 1;
            }
    }

}



Test clas
------------
@isTest
public class TestStringStack 
 {
public static testmethod void StringStackcheck()
{
    //Instantiate a StringStack.

    StringStack stack = new StringStack();
 // Set up some test data.

    String bottomString = 'Bottom String';
    String middleString = 'Middle String';
    String topString = 'Top String';

      // Call the push() method with multiple objects

    stack.push(bottomString);

    stack.push(middleString);
    stack.push(topString);

    // Verify that the 'top' object is the object we expected

    String peakValue = stack.peak();

    System.assertEquals(topString, peakValue);

    // Verify that the order of the objects is as we expected
    String popValue = stack.pop();
    System.assertEquals(topString, popValue);
    popValue = stack.pop();
    System.assertEquals(middleString, popValue);
    popValue = stack.pop();
    System.assertEquals(bottomString, popValue);
    System.assert(stack.isEmpty());

}
 }
 

my scenario is when i will click on new opportunity button a new opportunity page should open where i fill the details and click on save then it will redirect to the list page of opportunity where records save with edit and delete link when click on edit link edit page should open i have done till that but when i click on delete link it should deleted i am not abe to do for delete when i am deleting record a new bank page open
 

    <apex:page StandardController="Opportunity" Extensions="secondpage" >
        <apex:form >
        <apex:pageBlock >
    
        <apex:pageBlockButtons location="Top" >
         <apex:commandButton value="Save" action="{!saverec}"/> <br/><br/>
         
         <apex:commandLink action="{!editOpp}" value="Edit"/>
      <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
      <apex:commandLink action="{!deleteOpp}" value="Delete" />
     <apex:param value="{!opp.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:pageBlockButtons>
        <apex:pageblockSection >
           <apex:inputfield value="{!opp.Name}" />
            <apex:inputfield value="{!opp.StageName}"/>
             <apex:inputfield value="{!opp.AccountId}"/>
             <apex:inputfield value="{!opp.Amount}"/>
            <apex:inputfield value="{!opp.closeDate}"/>
       </apex:pageblockSection>
                </apex:pageBlock>   
        </apex:form>
    </apex:page>

----

    public class secondpage {
    
       
        Public Opportunity opp{get;set;}
        Public String op1;
         public id accid{set;get;}
       public String selectedAccId {get;set;}
          public String selectedoppId{get;set;}
        public secondpage(ApexPages.StandardController stdController) {
            
       
            Opp= (Opportunity)stdController.getRecord();
               
            
        }
       
       
        public PageReference saverec() {
           
            insert opp;
           
            pagereference pr = new pagereference('https://c.ap6.visual.force.com/apex/Opp2');
           
            return pr;
        }
    
    
        public Pagereference editOpp()
     {
         
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
     
     public Pagereference deleteOpp()
     {
            return null;
    
            }
     }

----

    <apex:page Controller="mycontroller1">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
    <apex:pageBlockTable value="{!Opportunitylst}" var="op">
    <apex:column value="{!op.Name}"/>
    <apex:column value="{!op.StageName}"/>
    <apex:column value="{!op.Amount}" />
    <apex:column value="{!op.accountId}"/>
    <apex:column value="{!op.CloseDate}"/>
    <apex:column headerValue="Action" >
      <apex:commandLink value="Edit /" action="{!editOpp}">
        <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        </apex:commandLink>
        
        <apex:commandLink action="{!deleteOpp}" value="Delete"/>
     <apex:param value="{!op.id}" assignTo="{!selectedAccId}" name="selectedAccId"/>
        
        
    </apex:column>                        
    </apex:pageBlockTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

----
                        
    public class mycontroller1 {
    
        public List<Opportunity> Opp{get;set;}
        Public List<Opportunity> Opportunitylst{get;set;}
        public String selectedAccId {get;set;}
    
    
      public PageReference deleteOpp() {
              
opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity where id=:selectedAccId];      
delete  opportunitylst;     
  return null;
              
              }
    
                 
                 
                 
        public mycontroller1(){
            Opportunitylst=[select Name,AccountId,Amount,CloseDate,StageName from Opportunity order by createdDate DESC limit 10 ];
         }
        public Pagereference editOpp()
     {
         p
           PageReference ref = new PageReference('/'+selectedAccId+'/e?retURL=%2F'+selectedAccId);
            return ref;
     }
    }

 
i want to create description custom fields on account and contact object
now i want to create a trigger on account object such that when i insert a record on account object contact shoul also be created with with the custom field updated same as account
please help me to achieve this