• viswanath reddy 53
  • NEWBIE
  • -2 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 20
    Replies
hi,
kindly help me with the test class for the following code.these are the names for the my vf pages. 
visualforce page1 name; check_in_button
visualforce page2 name :check_out_button
public with sharing class updateCheckInCheckOut {
    public string checkindate               {set;get;}
    public string checkoutdate              {set;get;}
    public id myid                          {set;get;}
    static Visit_Line_Item__c visit = new Visit_Line_Item__c();
    public updateCheckInCheckOut(Apexpages.StandardController stdController){
       myid = Apexpages.currentPage().getParameters().get(‘Id’);
       Visit_Line_Item__c visitlist = [select id,Checkin_Time__c,RecordType.Name,Account__c,Checkout_Time__c
                                         from Visit_Line_Item__c
                                         where id =:myid];
        checkindate = string.valueOf(visitlist.Checkin_Time__c);
        checkoutdate = string.valueOf(visitlist.Checkout_Time__c);
    }
    @remoteAction
    public static string updateCheckIn(Id visitId, string checkInDateTime, string latitude, string longitude){
        try{
            string checkInDate = checkInDateTime.split(‘T’)[0];
            Integer year = Integer.valueOf(checkInDate.split(‘-’)[0]);
            Integer month = Integer.valueOf(checkInDate.split(‘-’)[1]);
            Integer day = Integer.valueOf(checkInDate.split(‘-’)[2]);
            string checkInTime = checkInDateTime.split(‘T’)[1];
            Integer hour = Integer.valueOf(checkInTime.split(‘:’)[0]);
            Integer minute = Integer.valueOf(checkInTime.split(‘:’)[1]);
            Integer second = Integer.valueOf(checkInTime.split(‘:’)[2]);
            DateTime checkInDateTimeVal = DateTime.newInstanceGmt(year, month, day, hour, minute, second);
            visit = new Visit_Line_Item__c();
            visit.Id = visitId;
            visit.Checkin_Time__c = checkInDateTimeVal;
            visit.Check_In_Location__Latitude__s = Decimal.valueOf(latitude);
            visit.Check_In_Location__Longitude__s = Decimal.valueOf(longitude);
            visit.Check_In__c = True;
            update visit;
            return ‘Success Check In’;
        }
        catch(Exception e){
            return e.getMessage();
        }
    }
    @remoteAction
    public static string updateCheckOut (Id visitId, string checkOutDateTime, string latitude, string longitude){
        try{
            string checkOutDate = checkOutDateTime.split(‘T’)[0];
            Integer year = Integer.valueOf(checkOutDate.split(‘-’)[0]);
            Integer month = Integer.valueOf(checkOutDate.split(‘-’)[1]);
            Integer day = Integer.valueOf(checkOutDate.split(‘-’)[2]);
            string checkOutTime = checkOutDateTime.split(‘T’)[1];
            Integer hour = Integer.valueOf(checkOutTime.split(‘:’)[0]);
            Integer minute = Integer.valueOf(checkOutTime.split(‘:’)[1]);
            Integer second = Integer.valueOf(checkOutTime.split(‘:’)[2]);
            DateTime checkOutDateTimeVal = DateTime.newInstanceGmt(year, month, day, hour, minute, second);
            visit = new Visit_Line_Item__c();
            visit.Id = visitId;
            visit.Checkout_Time__c = checkOutDateTimeVal;
            visit.Check_Out_Location__Latitude__s = Decimal.valueOf(latitude);
            visit.Check_Out_Location__Longitude__s = Decimal.valueOf(longitude);
            visit.Check_Out__c = True;
            update visit;
            return ‘Success Check Out’;
        }
        catch(Exception e){
            return e.getMessage();
        }
    }
}

thanks in advance
regards
viswanath
Hi,
I am getting an error in below code. Could you please help me out.

if(trigger.isUnDelete && trigger.isafter)
    {
        set<Id> co=new set<Id>();
        for(Account a1:trigger.new)
        {
            co.add(a1.id);
        }
        list<Account> acc=[select id,name,Number_of_Contacts__c from Account where id in: (co)  ALL ROWS];
        undelete acc;
    }


Thanks.
We need to create a trigger. So the situation is like therev is a field in Account called Number_of_Contacts__c(number field). When we update the Number_of_Contacts__c feild, then the same number of Contacts will be created associated with that Account.

There can be 2 cases for update trigger:
1>   new value>old value
2>   new value<old value

I have completed the 1st case successfully, however I am Stuck in the 2nd case. Can you guys help me out. I am posting my 1st case of code here:

if(trigger.isUpdate && trigger.isafter)
    {
          list<Contact> conta=new list<Contact>();      
         set<Id> co=new set<Id>();
        for(Account a1:trigger.new)
        {
            co.add(a1.id);
        }
        list<Account> acc=[select id,name,Number_of_Contacts__c from Account where id in: (co)];
      
        for(Account a2:acc)
        {
            if(a2.Number_of_Contacts__c>trigger.oldMap.get(a2.Id).Number_of_Contacts__c)
            {
                a2.Sales_Rep__c='greater is working';
                for(Decimal i=trigger.oldMap.get(a2.Id).Number_of_Contacts__c+1;i<=a2.Number_of_Contacts__c;i++)
                 {
                        Contact c=new Contact();
                        c.AccountId=a2.Id;
                        c.LastName='Default Con'+ i;
                        conta.add(c);
                 }   
                insert conta;
            }
            if(a2.Number_of_Contacts__c<trigger.oldMap.get(a2.Id).Number_of_Contacts__c)
            {
                a2.Sales_Rep__c='smaller is working';
                for(Decimal i=trigger.oldMap.get(a2.Id).Number_of_Contacts__c-1;i>=a2.Number_of_Contacts__c;i--)
                 {
                      
                  // PLEASE HELP ME OUT FOR THIS PART


                 }   
              
            }
        }
    }
 
Hi,

I have a process builder workflow setup that sends out new task email notifications.  I would like to differentiate the the email notifications based on the queue that it is getting sent to.  

A simplified example is that we have one queue that is for the US Sales and another queue that is for International Sales.  I would like one style email template to be sent for the US and another for international.  I don't want to go off of the queue name since I would need to maintain that and this list will grow over time.

I originally was looking into custom metadata types, but not sure if that will work.  Any advise is greatly appreciated!  Thanks!
Is it possible to give create report access to a single user? Note: at profile level the create report access is not given.
I have a Scenario Where i have two fields as Status and description status is picklist and has Three Values as "One" ,"Two","Three" Now the scenario is if i select "one" then  the description  field should be editable(it should be visible but not be able to enter value for it) if i select "two" or "three" i should be able to edit that description 

Thanks in Adv
I am write this trigger. i need test class, how to write.

trigger ContactDuplicatemobile on Contact (before insert, before update) {


List<Contact> Contactlist = [select id,MobilePhone from Contact];


for(Contact c:Trigger.new)

{

for(Contact cc: Contactlist)

{


if(c.MobilePhone==cc.MobilePhone)

{

c.adderror('mobile number already exist');

}

} }

}
Hi group, 

Trying to get some help on a validation rule that has me stuck. What I'm trying to do is only allow an update to the Shipping Address, but only limited to three different profiles, and if a certain value is in the pick list. The code below is what I have so far.

AND(
OR(
ISCHANGED(ShippingStreet),
ISCHANGED(ShippingCity),
ISCHANGED(ShippingState),
ISCHANGED(ShippingPostalCode),
ISCHANGED(ShippingCountry),
OR(
NOT(ISPICKVAL( Hierarchy, "Value")),
$Profile.Name <> "ProfileA",
$Profile.Name <> "ProfileB",
$Profile.Name <> "ProfileC"
)))
  • May 15, 2020
  • Like
  • 0
Create two custom object “Merchant Account” and “Customer Account”. These two objects should be relatable to opportunity object. There is a count field and it should display the total number of opportunities they have.
 
Hello,

I'm working with French users, and in French, log a call = "Consigner un appel", New Event = "Nouvel Evénement"

The thing is that on the quick action to log a call / create a new event, it only shows "Consigne....." and "Nouven é..." whereas there are plenty of place to display those words.

How should I do to edit the size of the display of those icons ?! Pretty bad user experience with this.User-added image
Salesforce 18 digit record id can be same for two records only there case difference(small ad capital)?
For ex: One record is 0014T000004SW0gQAG and another is 0014T000004SW0GQAG. Both are same but difference is on 15th changracter small g and capital G.
Hello, I overrode the standard "new" button for a custom object with a lightning component. That component calls a Flow, which displays fields and creates the new record. The problem I'm encountering is that when the user clicks "new", instead of displaying my component/flow in a modal window, it takes them to a new page and displays all the fields across the entire page. How can I get it to display in a regular, smaller, modal window? 
When I download files as a zip file, is there a limit to how much I can download at once?
Spring 2020 release notes says that we can assign Tasks to queue.
I am able to assign task to any queue from task screen but it doesn't our problem of assigning task to queue using trigger or from process builder.

We have a requirement to create a new task and assigned to queue whenever any new case is created ?How can I achieve that?

Thanks,
Gaurav Seth
The customer is facing issue with enabling reCaptcha for web-to-case form to avoid spam case. Web-to-Case works fine when case is generated without reCaptcha but if it is checked then the cases does not created. Customer's current entitlement is Standard support level, hence need suggestion on alternatives to fix this issue
Hi all! We developed custom Lightning components and override standard actions for an object like View, Edit and some other with these components. It works OK, but now we've got the task to have two record types for this object and the new record type should have standard page layouts, not our components. The problem is overriding standard actions affects all record types. Is there any way to achieve what we need?

I have an Object which is n master-detail with another object 
When A record in object A is created 3 records are created in Object b automatically.(I did this through process builder)
I want to put the component on object A to show all the associate record of object B and billing details of it.

Thanks in Advance!

I am trying to update a Picklist value "status ='Closed'" of a custom object Service_Request__c based on Picklist value "Status = 'Completed' on Service_Line__c record, basically this should happen after I update Status = 'Completed' on Service_Line__c. Service_Line__c Custom Object has a Master-Detail with Service_Request__c. Thanks in Advance.
I have a VF page with look up field which is now migrated to lightning experience and working fine. However in SF1 the lookup field shows up as a plain inputField. After googling I now know the lookup fields are not supported in SF1, but the posts are quite old. I wonder if lookup fields are allowed in the latest release of salesForce? Also is there any other way to get the look up working in SF1?
Recently i have written a test class for @remoteaction.i got 79% with error.how to resolve this error and improve code coverage?
apex class:
global class Rfleet_Searchaddress {
    public String StNumber {get;set;}
    public String Bcity {get;set;}
    public String BPostalcode {get;set;}
    public String BCountry {get;set;}
    public String Snumber {get;set;}
    public String street {get;set;}
    public Boolean refreshPage {get;set;}
    string Id;
    list < Account > updateAdd = new list < Account > ();
	//This method is constructor
    public Rfleet_Searchaddress(ApexPages.StandardController controller) {
            id = ApexPages.currentPage().getParameters().get('id');
            refreshPage = false;
        }
        //This method is autosave the addresses
    public void autosave() {
            for (Account updatelist: [SELECT id, Rfleet_Main_Address_Number__c, Rfleet_Main_address_Street__c, BillingAddress, BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet FROM Account where id = : id]) {
                updatelist.BillingStreet = Snumber + ' ' + street; //StNumber;
                updatelist.BillingCity = Bcity;
                updatelist.BillingPostalCode = BPostalcode;
                updatelist.BillingState = '';
                updatelist.BillingCountry = BCountry;
                updatelist.Rfleet_Main_Address_Number__c = Snumber;
                updatelist.Rfleet_Main_address_Street__c = street;
                updateAdd.add(updatelist);
            }
        try{
            update updateAdd;
        }catch(DmlException e) {
		system.debug('update--->' + updateAdd);
            }
            refreshPage = true;
        }
        //This method is remote action
        @RemoteAction
	global static list < String > restapi(string accName) {
        string jsonStr;
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setHeader('Accept', 'application/JSON');
        req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q=' + EncodingUtil.urlEncode(accName, 'UTF-8')); //+'&'+'limit'+'='+'10');// 
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        system.debug('res1===>' + res.getBody());
        List < String > calOut1 = new List < String > ();
        JSON2Apex parsed = JSON2Apex.parse(res.getBody());
        for (JSON2Apex.Features f: parsed.Features) {
            JSON2Apex.Properties p = f.Properties;
            calOut1.add(p.label + ' ' + 'FRANCE');
        }
        return calOut1;
    }
}
json2apex class:
public class JSON2Apex {

    public String query;
    public String version;
    public String licence;
    public List<Features> features;
    public String type;
    public String attribution;

    public class Geometry {
        public List<Double> coordinates;
        public String type;
    }

    public class Features {
        public Geometry geometry;
        public String type;
        public Properties properties;
    }

    public class Properties {
        public String city;
        public String label;
        public String id;
        public String postcode;
        public String name;
        public String citycode;
        public String context;
        public Double score;
        public String type;
    }

    
    public static JSON2Apex parse(String json) {
        return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
    }
    
    static testMethod void testParse() {
        String json = '{\"query\": \"8\", \"version\": \"draft\", \"licence\": \"ODbL 1.0\", \"features\": [{\"geometry\": {\"coordinates\": [5.600741, 43.28252], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Aubagne\", \"label\": \"Route Nationale 8 13400 Aubagne\", \"id\": \"13005_XXXX_b0c6c8\", \"postcode\": \"13400\", \"name\": \"Route Nationale 8\", \"citycode\": \"13005\", \"context\": \"13, Bouches-du-Rh\\u00f4ne, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6540636363636363, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.864773, 43.132774], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_a33650\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6526818181818181, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [45.136426, -12.845884], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ouangani\", \"label\": \"Route D\\u00e9partementale 8 97670 Ouangani\", \"id\": \"97614_XXXX_704587\", \"postcode\": \"97670\", \"name\": \"Route D\\u00e9partementale 8\", \"citycode\": \"97614\", \"context\": \"976, Mayotte\", \"score\": 0.6507545454545454, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.86687, 43.132284], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_9346fc\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6481181818181817, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [3.242916, 43.379135], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"B\\u00e9ziers\", \"label\": \"Chemin Rural 8 34500 B\\u00e9ziers\", \"id\": \"34032_XXXX_ddb1db\", \"postcode\": \"34500\", \"name\": \"Chemin Rural 8\", \"citycode\": \"34032\", \"context\": \"34, H\\u00e9rault, Languedoc-Roussillon\", \"score\": 0.6467545454545454, \"type\": \"locality\"}}], \"type\": \"FeatureCollection\", \"attribution\": \"BAN\"}';
        JSON2Apex obj = parse(json);
         
        System.assert(obj != null);
    }
}


mockgenerator test class:
@isTest
global class Rfleet_MockHttpResponseGenerator_Test implements HttpCalloutMock {
    
  global HTTPResponse respond(HTTPRequest req) {        
        // Optionally, only send a mock response for a specific endpoint
        // and method.
        System.assertEquals('http://api-adresse.data.gouv.fr/search/?q='+'france', req.getEndpoint());
        System.assertEquals('GET', req.getMethod());
        
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('{"foo":"bar"}');
        res.setStatusCode(200);
        return res;

                        
                }
}
Test class:
@isTest
public class Rfleet_Searchaddress_test {
    @isTest static void Testsearchaddress() {
    
        Account testAccount = new Account(Name='chinna',Montant__c=5);
        insert testAccount;
        
        testAccount.BillingStreet='chengalpattu';
        
        update testAccount;
        Account myTestTrainee = [SELECT id From Account LIMIT 1];
        PageReference myVfPage = Page.RFLEET_Searchaddress;
        system.test.setCurrentPage(myVfPage);
        
        ApexPages.currentPage().getParameters().put('id', myTestTrainee.id);//Pass Id to page
        ApexPAges.StandardController sc = new ApexPages.StandardController(myTestTrainee);
        Rfleet_Searchaddress apextestclass=new Rfleet_Searchaddress(sc);
        apextestclass.autosave();
        String param ='Base Product';
        
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        
        req.requestURI = 'http://api-adresse.data.gouv.fr/search/?q=';  
        req.httpMethod = 'GET';
        RestContext.request = req;
        RestContext.response = res;
        
        Rfleet_Searchaddress.restapi('jso');
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new Rfleet_MockHttpResponseGenerator_Test());
        Test.stopTest();
    }    

}