• Pramod Nishane 17
  • NEWBIE
  • 95 Points
  • Member since 2017
  • Salesforce Consultant
  • Varasi

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 28
    Replies
Global class AnimalLocator {
    Global static String getAnimalNameById(Integer numb){
        String response;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+numb);
        request.setMethod('GET');
        HttpResponse resp = http.send(request);
        if(resp.getStatusCode()==200){
            Map<String,Object> results = (Map<String,Object>) JSON.deserializeUntyped(response.getBody());
            Map<String,Object> animal = (Map<String,Object>)results.get('animal');
            response = (String)animal.get('name');
        }
        return response;
    }
}
I'm getting the error "Method does not exist or incorrect signature : void getBody() from String type "
 
Control Processes with Queueable Apex challenge of Asynchronous Apex module 
I wrote the bellow queueable class
public class AddPrimaryContact implements Queueable{
    public List<Contact> contacts = new List<Contact>();
    List<Account> accs = [Select Id, Name, BillingState from Account];
    public void AddPrimaryContact(List<Account> accs){
    
      for(Account a : accs){
        Contact con = new Contact();
        con.AccountID = a.Id;
        con.LastName = 'Contact of '+a;
        contacts.add(con);
        system.debug('con check'+con);
      }
       insert contacts; 
    }
  public void execute(QueueableContext context){
        for (Contact cont : contacts) {
        cont.MailingState = cont.Account.BillingState;
        }
        update contacts;
    }
}

And then wrote the below test class
@isTest
public class AddPrimaryContactTest {
    
    @testSetup
    static void setup(){
        List<Account> accs = new List<Account>();
        for (Integer j=0; j<2; j++){
            if(j==0){
                for (Integer i=0; i<50; i++){
                    accs.add(new Account( name='TestC Account'+i, BillingState='NY'));
                }
            }
            else{
                 for (Integer i=0; i<50; i++){
                    accs.add(new Account( name='TestD Account'+i, BillingState='CA'));
                }   
                    
             }
            
        }
        insert accs;
    }
    
    static testMethod void testQueueable(){
        List<Account> accts = [Select Id, Name, BillingState from Account where BillingState = 'NY' OR BillingState = 'CA'];
    	AddPrimaryContact addressput = new AddPrimaryContact(accts);
        Test.startTest();
        System.enqueueJob(addressput);
        Test.stopTest();
        
        System.assertEquals(50, [select count() from Contact where MailingState = 'NY']);
        System.assertEquals(50, [select count() from Contact where MailingState = 'CA']);
    }

}

The error I'm getting is "constructor not defined [AddPrimaryContact].(list). And when I run the queueable class in Anonymous execution I don't see SOQL querries running. What could be the issue here ?
I have created a lead, and now it won't let me convert. This is th error message that I am receiving:
Converting A Lead
 I am trying to access additional information about a failed batch job. 

I read the doc at https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_batches_get_info_all.htm
The solution there is to build a URL to form a GET request to return information about a particular job.

Here is the general form of the URL:
https://instance_name—api.salesforce.com/services/async/APIversion/job/jobid/batch

So I then substituted the specifics of my org into this url, and the URL becomes 
https://NA##—api.salesforce.com/services/async/42/job/7071J00008J6XVu/batch (## is instance server)

This should take me to information about the batch. But it doesn't.
It redirects me to 
https://xn--na##api-516c.salesforce.com/services/async/42/job/7071J00008J6XVu/batch

And then I get the following error message in my web browser: 
"This site can’t be reached
xn--naXXapi-516c.salesforce.com’s server IP address could not be found.
Try running Network Diagnostics.
DNS_PROBE_FINISHED_NXDOMAIN"

No information about my batch job is provided.

What is this website?
I formed the URL correctly, so what is going wrong?

SF Support said I needed to access it via API, but the docs said a simple GET request shoudl return info...so what lightweight tool can i use to just get Apex batch info from a jobid?
I am trying to figure out how to prompt a user to create an Opportunity after they've saved an Account that meets our specific criteria. I know there is functionality to do this but I'm not sure how to trigger it this way specifically.  

I've Googled like a mad man and can't seem to find a solid solution so any help would be appreciated. 
Hello I have a problem, the notification via email when changing the owner of a lead does not work. When changing the owner of a lead, I mark the check to send an email and nothing happens. The owner changes but the mail never arrives. It should be noted that this type of email arrives at another type of notifications from the organization, only the problem is in the change of owner manually.

Has someone happened to you?
Is there some kind of configuration that I should review?

I'd appreciate your help.

Regards
Hi there,

I have a JSON that is being returned from an HTTP Callout and for which I am using an Apex Class to deserialize. Everything is working as expected when I test it through the developer console. But when I write test coverage, the class for which I am deserializing to is showing up as not covered by the test class.

Does the JSON.deserialize cover the class that it's deserializing to or does it not? Thanks.

Sanch.
 
Map<String,String> Selected = new Map<String,String>();
Map<String,String> customvalues = new Map<String,String>();
List<String> lst = new List<String>();
for(String t: customvalues.keySet()){
    String test= customvalues.get(t);
for(String s: Selected.keySet()){
    String Sample= Selected.get(s);
//how to restrict duplicates here intering into this loop
if(test.equals(s)){ lst.add(Sample);
    }
  }
}
if(lst!=null){
for(Integer i=0;i<=lst.size();i++){
Lead le = new Lead();
le.LastName=lst[0];
le.Company = lst[1];
le.Status = lst[2];
le.LightiningEd__City__c = lst[3];
le.LightiningEd__State__c = lst[4];
le.LightiningEd__Country__c = lst[5];
LeadList.add(le);
} if(!LeadList.isEmpty()){
upsert LeadList;
}

Thanks I adavance,If anybody having idea please let me know.
Hi All,

I have Account object and Issue(custom object). Issue object have look up relation with Account. I have a button called create Issue on Account object which is overriden by VF page. When I click on create Issue, i want to render some fields based on associated account region. so in my controller i want to check something like below.
If(Issue__c.Account__r.Region__c == 'abc') is this the correct way? I am getting the expected value. Can some one please help me with this pls?

Thanks.
  • February 02, 2018
  • Like
  • 0

I would like to create a formula field on the oportunity that looks up the "FirstName" of the related contact. To complicate matters we may have more than one contact related to an opportunity, so I want to get the primary contact, which may be assigned by another field called "PrimaryContact__c". 

Is this possible with a formula field? Do I need to write a soql query to accomplish this? What's the best way to make this work?

Thanks in advance for your help!

Global class AnimalLocator {
    Global static String getAnimalNameById(Integer numb){
        String response;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+numb);
        request.setMethod('GET');
        HttpResponse resp = http.send(request);
        if(resp.getStatusCode()==200){
            Map<String,Object> results = (Map<String,Object>) JSON.deserializeUntyped(response.getBody());
            Map<String,Object> animal = (Map<String,Object>)results.get('animal');
            response = (String)animal.get('name');
        }
        return response;
    }
}
I'm getting the error "Method does not exist or incorrect signature : void getBody() from String type "
 
Hi

Here my requirement is display all account records and mass update the records here condition is if the record check box is checked (true)then only records need to be update with out selecting check box record does not update  
(the code is updating the records with out selecting the check box but i need after selecting the checkbox then only update the records​)

User-added image
here my code is

apex:
public with sharing class massupdate
{
  
    @AuraEnabled
    public static list < Account > fetchAccount()
    {
        // query 10 records from account with their relevant contacts and return query.
        List < Account > lstOfAcc = [select Name, AnnualRevenue, BillingState, Website,Rating,Phone from Account limit 10 ];
        return lstOfAcc;
    }
     // method for update records after inline editing  
    @AuraEnabled
    public static List < account > saveAccount(List<Account> lstAccount) {
        update lstAccount;
        return lstAccount;
    }

 
}
-------------------------------------
component

<aura:component controller="massupdate">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="ListOfAccount" type="Account[]" description="store accounts with there child contacts"/>
    <div>
         <table class="table table-bordered table-hover" width="70%">
            <thead>
                <tr>
                    <th width="5%"> <strong>  Select </strong> </th>
                    <th width="20%"> <strong>  Id </strong> </th>
                    <th width="20%"> <strong>  Name </strong> </th>
                    <th width="20%"><strong> Website </strong></th>
                    <th width="20%"><strong> Phone </strong></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.ListOfAccount}" var="ac">
                    <tr>
                        <td><ui:inputCheckbox text="{!ac.Id}" aura:id="boxPack" value="" /></td>
                        <td> <a href="{! '/'+ac.Id}"> {!ac.Id} </a> </td>
                        <td><ui:inputText value="{!ac.Name}"/>   </td>
                        <td><ui:inputText value="{!ac.Website}"/>    </td>
                        <td><ui:inputText value="{!ac.Phone}"/>  </td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
            </div>
    <br/>
     <lightning:button label="Save" onclick="{!c.Save}" variant="success"/>
     <lightning:button label="Cancel" onclick="{!c.Cancel}" variant="success"/>
</aura:component>

-----------------------------------------------
controller
({
    doInit: function(component, event, helper) {
        //call apex class method
        var action = component.get('c.fetchAccount');
        action.setCallback(this, function(response)
                           {
            //store state of response
            var state = response.getState();
            if (state === "SUCCESS") {
                //set response value in ListOfAccount attribute on component.
                component.set('v.ListOfAccount', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    Save: function(component, event, helper) 
    {                            
        var newAcc = component.get("v.ListOfAccount");
        var action = component.get("c.saveAccount");
        action.setParams({"lstAccount": newAcc });
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") 
            {
                var name = a.getReturnValue();
                component.set("v.ListOfAccount", name);
                alert('Updated...');
                location.reload();
            }
        })
        $A.enqueueAction(action);
    },
    Cancel: function(component, event, helper) 
    {    
        alert('Clicked on cancled ...');
         location.reload();
    }
})


 
I need help to query on Task Event to get Opportunity custom fields like Campaign name and Product name. I would like to filter my tasks related to Oppty and Lead based on product name and campaign name.

String LeadObjName= 'Lead'; String OpportunityObjName= 'Opportunity'; String Completedsatatus= 'Completed';
String queryStr='select Id, Subject, Status,ActivityDate,Priority, OwnerId, Owner.Name, Owner.IsActive,Description,WhoId,Who.Name,WhatId, What.Name,AccountId,Account.Name '; queryStr+=' from Task where OwnerId = :userId and (Who.Type =:LeadObjName OR What.Type = :OpportunityObjName ) '; queryStr+=' and Status !=:Completedsatatus'; queryStr+=' order by ActivityDate ASC, Priority DESC';
Ques: We want to access opportunity and lead custom fields in my query but not able to add custom fields here in this query Thanks in Advance!
  • January 28, 2018
  • Like
  • 0
Hello All,
I am trying to get lightning page URL using (window.parent.location). I am facing cross domain error.
Is there any solution to get lightning page URL and get parameters from lightning URL?

Thanks
trigger HelloWorld on Lead (before update) {
    For (Lead l: Trigger.new) {
        l.FirstName = 'Hello';
        l.LastName = 'World';
        
    }

}
This Trigger works as expected in Classic, but will update a New record in Lightning.  Why?
 
Hi All,
I am new to lightning components, when i am click on lightning tab getting emty values.
User-added image
Apex Controller********
public with sharing class CaseController 
{
    @AuraEnabled
    public static List<Case> getCases() 
    {
        List<Case> cases= [SELECT Id, CaseNumber, AccountId, ContactId, ContactPhone, ContactEmail, Origin, Reason, Status FROM Case Where Status=:'Closed'];

        //Add isAccessible() check
        return Cases;
    }
}

Component**********
<aura:component >
    <aura:attribute name="Case" type="Case" />
    
        <lightning:card variant="Narrow" title="{!v.Case.CaseNumber}" 
                        iconName="standard:Case">
            <aura:set attribute="actions">
                <lightning:button name="details" label="Details" onclick="{!c.goToRecord}" />
            </aura:set>    
            <aura:set attribute="footer">
                Account Name: <lightning:badge label="{!v.Case.AccountId}"/>
            </aura:set>
            <p class="slds-p-horizontal_small">
                {!v.Case.ContactId}
            </p>
            <p class="slds-p-horizontal_small">
                {!v.Case.ContactPhone}
            </p>
            <p class="slds-p-horizontal_small">
                {!v.Case.ContactEmail}
            </p>
        </lightning:card>

</aura:component>

ComponentList********
<aura:component implements="force:appHostable" controller="CaseController">
    <!-- Handle component initialization in a client-side controller -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <!-- Dynamically load the list of cases -->
    <aura:attribute name="cases" type="Case[]"/>
    <aura:attribute name="caseList" type="Case[]"/>
    <aura:attribute name="totalcases" type="Integer"/>
    
    <!-- Page header with a counter that displays total number of cases -->
    <div class="slds-page-header slds-page-header_object-home">
        <lightning:layout >
            <lightning:layoutItem >
                <lightning:icon iconName="standard:Case" />
            </lightning:layoutItem>
            <lightning:layoutItem class="slds-m-left_small">
                <p class="slds-text-title_caps slds-line-height_reset">Cases</p>
                <h1 class="slds-page-header__title slds-p-right_x-small">Case Viewer</h1>
            </lightning:layoutItem>
        </lightning:layout>
    
        <lightning:layout >
            <lightning:layoutItem >
                <p class="slds-text-body_small">{!v.totalcases} Cases • View Cases Based on Case Origin</p>
            </lightning:layoutItem>
        </lightning:layout>
    </div>
    
    <!-- Body with dropdown menu and list of cases -->
    <lightning:layout >
        <lightning:layoutItem padding="horizontal-medium" >
            <!-- Create a dropdown menu with options -->
            <lightning:select aura:id="select" label="Case Origin" name="Source" 
                              onchange="{!c.handleSelect}" class="slds-m-bottom_medium">
                <option value="">-- Select a Case Origin --</option>
                <option value="Phone" text="Phone"/>
                <option value="Email" text="Email"/>
                <option value="Web" text="Web"/>
                <option value="All" text="All"/>
            </lightning:select>
    
            <!-- Iterate over the list of cases and display them -->
            <aura:iteration var="Case" items="{!v.cases}">
                <!-- If you’re using a namespace, replace with myNamespace:cases-->
                <c:Cases case="{!case}"/>
            </aura:iteration>
        </lightning:layoutItem>
    </lightning:layout>
</aura:component>

Controller********
({
    doInit : function(component, event, helper) {
        // Retrieve cases during component initialization
        helper.loadcases(component);
    },
    
    handleSelect : function(component, event, helper) {
        var cases = component.get("v.cases");
        var caseList = component.get("v.caseList");

        //Get the selected option: "Phone", "Email", "Web", or "All"
        var selected = event.getSource().get("v.value");
    
        var filter = [];
        var k = 0;
        for (var i=0; i<caseList.length; i++){
            var c = caseList[i];
            if (selected != "All"){
                if(c.Origin == selected) {
                    filter[k] = c;
                    k++; 
                }
            }
            else {
                   filter = caseList;
            }       
        }
        //Set the filtered list of cases based on the selected option
        component.set("v.cases", filter);
        helper.updateTotal(component);
    }
})

Helper**********
({
   loadcases : function(cmp) {
        // Load all case data
        var action = cmp.get("c.getCases");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.cases", response.getReturnValue());
                cmp.set("v.caseList", response.getReturnValue());
                this.updateTotal(cmp);
            }

            // Display toast message to indicate load status
            var toastEvent = $A.get("e.force:showToast");
            if (state === 'SUCCESS'){
                toastEvent.setParams({
                    "title": "Success!",
                    "message": " Your cases have been loaded successfully."
                });
            }
            else {
                toastEvent.setParams({
                        "title": "Error!",
                        "message": " Something has gone wrong."
                });
            }
            toastEvent.fire();
        });
         $A.enqueueAction(action);
    },
     
    updateTotal: function(cmp) {
      var cases = cmp.get("v.cases");
      cmp.set("v.totalcases", cases.length);
    }
})
Control Processes with Queueable Apex challenge of Asynchronous Apex module 
I wrote the bellow queueable class
public class AddPrimaryContact implements Queueable{
    public List<Contact> contacts = new List<Contact>();
    List<Account> accs = [Select Id, Name, BillingState from Account];
    public void AddPrimaryContact(List<Account> accs){
    
      for(Account a : accs){
        Contact con = new Contact();
        con.AccountID = a.Id;
        con.LastName = 'Contact of '+a;
        contacts.add(con);
        system.debug('con check'+con);
      }
       insert contacts; 
    }
  public void execute(QueueableContext context){
        for (Contact cont : contacts) {
        cont.MailingState = cont.Account.BillingState;
        }
        update contacts;
    }
}

And then wrote the below test class
@isTest
public class AddPrimaryContactTest {
    
    @testSetup
    static void setup(){
        List<Account> accs = new List<Account>();
        for (Integer j=0; j<2; j++){
            if(j==0){
                for (Integer i=0; i<50; i++){
                    accs.add(new Account( name='TestC Account'+i, BillingState='NY'));
                }
            }
            else{
                 for (Integer i=0; i<50; i++){
                    accs.add(new Account( name='TestD Account'+i, BillingState='CA'));
                }   
                    
             }
            
        }
        insert accs;
    }
    
    static testMethod void testQueueable(){
        List<Account> accts = [Select Id, Name, BillingState from Account where BillingState = 'NY' OR BillingState = 'CA'];
    	AddPrimaryContact addressput = new AddPrimaryContact(accts);
        Test.startTest();
        System.enqueueJob(addressput);
        Test.stopTest();
        
        System.assertEquals(50, [select count() from Contact where MailingState = 'NY']);
        System.assertEquals(50, [select count() from Contact where MailingState = 'CA']);
    }

}

The error I'm getting is "constructor not defined [AddPrimaryContact].(list). And when I run the queueable class in Anonymous execution I don't see SOQL querries running. What could be the issue here ?