• Aryan Jha
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 12
    Replies
@istest
public class AccountProcessorTest {
@istest
    static void CountContactTest()
    {
        List<Account>accounts=new List<Account>();
        for(Integer i=0;i<300;i++)
        {
            accounts.add(new Account(Name='test account'+i));
        }
        insert accounts;
        List<Contact>contacts=new List<Contact>();
        List<Id>accountId=new List<Id>();
        for(Account a:accounts)
        {
            contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
            accountId.add(a.id);    
        }
        insert contacts;
        Test.startTest();
        AccountProcessor.countContacts(accountId);
        Test.stopTest();
        List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
        for(Account acc:accs)
        {
            system.assertEquals(1,acc.Number_Of_Contacts__c);
        }
    }


}
public class AccountProcessor {
    @future
    public static void countContacts(List<ID>accountIds)
    {
        List<Account>accounts=[SELECT Id,(SELECT Id FROM Contacts) FROM Account WHERE Id IN:accountIds];
        for(Account acc:accounts)
        {
            acc.Number_Of_Contacts__c=acc.Contacts.size();
}
        update accounts;
    }


}

@istest
public class AccountProcessorTest {
@istest
    static void CountContactTest()
    {
        List<Account>accounts=new List<Account>();
        for(Integer i=0;i<300;i++)
        {
            accounts.add(new Account(Name='test account'+i));
        }
        insert accounts;
        List<Contact>contacts=new List<Contact>();
        List<Id>accountId=new List<Id>();
        for(Account a:accounts)
        {
            contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
            accountId.add(a.id);    
        }
        insert contacts;
        Test.startTest();
        AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
        for(Account acc:accs)
        {
            system.assertEquals(1,acc.Number_Of_Contacts__c);
        }
    }
}
public class AccountContacts {
    public static Account Accountwithnocontacts()
    {
        Account a=new Account();
        a.Name='aryanjha';
        a.Phone='901727392';
        return a;
    }
    public static Account Accountwithcontacts()
    {
        Account acc=[SELECT Id,name FROM Account WHERE Name='Voltas'];
        for(Account a:acc)
        {
            Contact con=new Contact();
            con.firstname='Lucky';
            acc.add(con);
            return acc;
        }
    }

}
@isTest
public class testclassex {
@isTest static void Tempwarm()
{
    Decimal cel=TemperatureConvertor.FahrenheitToCelsius(70);
    system.assertEquals(21.3,cel);
    
        
}
}
@isTest
public class AddPrimaryContactTest {
@testSetup 
    static void setup() {
        List<Account> accounts = new List<Account>();
        // add 50 NY account
        for (Integer i = 0; i < 50; i++) {
        accounts.add(new Account(Name='NY'+i, billingstate='NY'));
        }
         // add 50 CA account
        for (Integer j = 0; j < 50; j++) {
        accounts.add(new Account(Name='CA'+j, billingstate='CA'));
           }
        insert accounts;
      }
       static testmethod void testQueueable(){
        contact a=new contact(Lastname='mary', Firstname='rose'); 
        Test.startTest();        
        AddPrimaryContact updater=new AddPrimaryContact(a, 'CA');
        System.enqueueJob(updater);
        Test.stopTest(); 
      
        System.assertEquals(50, [SELECT count() FROM Contact WHERE Lastname='mary' AND Firstname='rose']) ;                      
    }   
}
public class AnimalLocator
{
public static String getAnimalNameById(Integer id)
{
String returnval=null;
Http http=new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint('https://th-apex-http-callout.herokuapp.com/animals/id'+id);
request.setMethod('GET');
HttpResponse response=http.send(request);
if(response.getStatusCode()==200)
{
Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
Map<String,Object>result=(Map<String,Object>)jsonbody.get('animal');
returnval=String.valueof(result.get('name'));
}
return retunvalue;
}
}

@isTest
global class AnimalLocatorMock implements HttpCalloutMock
{
global HttpResponse respond(HttpRequest request)
{
HttpResponse response=new Httpresponse();
response.setheader('Content-Type','application/json');
response.setbody('{"animal":{"id":1,"name":"tiger","eats":"deer","says":"roar"}}');
response.setStatusCode(200);
return response;

}
}
@isTest
private class AnimalLocatorTest()
{
@isTest static void testAnimalNamebyId()
{
Test.setMock(HttpCalloutMock.class,new AnimalLocatorMock());
String result= AnimalLocator.getAnimalNameById(1);
system.assertNotEquals(null,result,'the callout returns a null response');
system.assetEquals('tiger',result);
}
}
public class AnimalLocator
{
public static String getAnimalNameById(Integer id)
{
Http http=new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint('https://th-apex-http-callout.herokuapp.com/animals/id');
request.setMethod('GET');
HttpResponse response=http.send(request);
if(response.getStatusCode()==200)
{
Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
List<Object>result=(List<Object>)jsonbody.get('animal');
String returnvalue=(String) result.get('id');
return retunvalue;
}
}
}
public class YoutubeApi
{
public static String Nameoftheyoutubechannel(String ChannelName)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.googleapis.com/youtube/v3');
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
{
    Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
    Map<String,Object>result=(Map<String,Object>)jsonbody.get('SNIPPET');
    String id=(String) result.get('ChannelId');

    return id;
}
else
{
    system.debug(+ response.getStatusCode() + '' +response.getStatus());
}
}
}
public class YoutubeApi {
    public static String youtubechannelid(String channelname)
    {
        Http http =new Http();
        HttpRequest res=new HttpRequest();
        res.setEndpoint('https://www.googleapis.com/youtube/v3');
        res.setMethod('GET');
        HttpResponse resp=http.send(res);
        if(resp.getStatusCode()==200)
        {
            Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(res.getBody());
            List<object>result=(List<Object>)jsonbody.get('ChannelId');
            system.debug( result);
            return result;
        }
        
    }

}
public class CurrencyConvertorClass {
public static Decimal currencytoinr(Decimal eur)
{
    Http http=new Http();
    HttpRequest request=new HttpRequest();
    request.setEndpoint('http://api.exchangeratesapi.io/latest');
    request.setmethod('GET');
    HttpResponse res=http.send(request);
    if(res.getStatusCode()==200)
    {
        Map<String,Object>result=(Map<String,Object>)JSON.deserializeUntyped(res.getBody());
        system.debug(result);
        Map<Integer,Object>listrates=(Map<Integer,Object>)result.get('rates');
        Decimal conversionRate=(Decimal)listrates.get('INR');
        inr=eur*conversionrate;
        return inr;
    }
}
}

Decimal convertedAmt=CurrencyConvertorClass.currencytoinr(287.6);
system.debug(convertedAmt);
trigger ClosedOpportunityTrigger on Opportunity (After insert,After update) {
List<Task>taskofopportunity=new List<Task>();
for(Opportunity opp:Trigger.new)
{
if(opp.StageName=='Closed_won')
{
Task t=new Task();
t.WhatId=opp.Id;
t.Subject='Follow Up Test Task';
taskofopportunity.add(t);
}
}
insert taskofopportunity;

}
public class oppsoftrigger1
{
public static void triggeronoppsandcontact(List<Opportunity>opp)
{
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE CloseDate=TODAY AND Id IN:Trigger.new]);
for(Opportunity o:opp)
{
Contact c=new Contact();
c.FirstName='neha';
c.LastName='mehra';
c.AccountId=o.AccountId;
conlist.add(c);
}
insert conlist;
}
}
Then i make a trigger on opportunity
trigger oppsontrigger on Opportunity (after insert) {
oppsoftrigger.triggeronoppandcontact(Trigger.new);
}
trigger Opps_trigger1 on Opportunity (after insert) {
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE AccountID IN:Trigger.new]);
for(Opportunity o:Trigger.new)
{
c.AccountID=o.AccountID;
c.FirstName='aryan';
c.LastName='jha';
conlist.add(c);
}
insert conlist;
}
trigger AccountAddressTrigger on Account(Before insert,before update) {
 for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }
}
List<Contact> conList = new List<Contact>{
    new Contact(FirstName='aryan',LastName='jha',description='computer'),
        new Contact(FirstName='atul',LastName='kumar',description='Buisness')};                                };
system.debug(+ conList );
insert conList;
List<Contact>Listtoupdate=new List<Contact>();
for(Contact con: conList){
con.Title='i am a computer analyst';
con.phone='9827373773';
system.debug(+ Listtoupdate );
}
update conList;
trigger Opps_trigger1 on Opportunity (after insert) {
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE AccountID IN:Trigger.new]);
for(Opportunity o:Trigger.new)
{
c.AccountID=o.AccountID;
c.FirstName='aryan';
c.LastName='jha';
conlist.add(c);
}
insert conlist;
}
@istest
public class AccountProcessorTest {
@istest
    static void CountContactTest()
    {
        List<Account>accounts=new List<Account>();
        for(Integer i=0;i<300;i++)
        {
            accounts.add(new Account(Name='test account'+i));
        }
        insert accounts;
        List<Contact>contacts=new List<Contact>();
        List<Id>accountId=new List<Id>();
        for(Account a:accounts)
        {
            contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
            accountId.add(a.id);    
        }
        insert contacts;
        Test.startTest();
        AccountProcessor.countContacts(accountId);
        Test.stopTest();
        List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
        for(Account acc:accs)
        {
            system.assertEquals(1,acc.Number_Of_Contacts__c);
        }
    }


}
public class AccountProcessor {
    @future
    public static void countContacts(List<ID>accountIds)
    {
        List<Account>accounts=[SELECT Id,(SELECT Id FROM Contacts) FROM Account WHERE Id IN:accountIds];
        for(Account acc:accounts)
        {
            acc.Number_Of_Contacts__c=acc.Contacts.size();
}
        update accounts;
    }


}

@istest
public class AccountProcessorTest {
@istest
    static void CountContactTest()
    {
        List<Account>accounts=new List<Account>();
        for(Integer i=0;i<300;i++)
        {
            accounts.add(new Account(Name='test account'+i));
        }
        insert accounts;
        List<Contact>contacts=new List<Contact>();
        List<Id>accountId=new List<Id>();
        for(Account a:accounts)
        {
            contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
            accountId.add(a.id);    
        }
        insert contacts;
        Test.startTest();
        AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
        for(Account acc:accs)
        {
            system.assertEquals(1,acc.Number_Of_Contacts__c);
        }
    }
}
public class AnimalLocator
{
public static String getAnimalNameById(Integer id)
{
String returnval=null;
Http http=new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint('https://th-apex-http-callout.herokuapp.com/animals/id'+id);
request.setMethod('GET');
HttpResponse response=http.send(request);
if(response.getStatusCode()==200)
{
Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
Map<String,Object>result=(Map<String,Object>)jsonbody.get('animal');
returnval=String.valueof(result.get('name'));
}
return retunvalue;
}
}

@isTest
global class AnimalLocatorMock implements HttpCalloutMock
{
global HttpResponse respond(HttpRequest request)
{
HttpResponse response=new Httpresponse();
response.setheader('Content-Type','application/json');
response.setbody('{"animal":{"id":1,"name":"tiger","eats":"deer","says":"roar"}}');
response.setStatusCode(200);
return response;

}
}
@isTest
private class AnimalLocatorTest()
{
@isTest static void testAnimalNamebyId()
{
Test.setMock(HttpCalloutMock.class,new AnimalLocatorMock());
String result= AnimalLocator.getAnimalNameById(1);
system.assertNotEquals(null,result,'the callout returns a null response');
system.assetEquals('tiger',result);
}
}
public class YoutubeApi
{
public static String Nameoftheyoutubechannel(String ChannelName)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.googleapis.com/youtube/v3');
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
{
    Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
    Map<String,Object>result=(Map<String,Object>)jsonbody.get('SNIPPET');
    String id=(String) result.get('ChannelId');

    return id;
}
else
{
    system.debug(+ response.getStatusCode() + '' +response.getStatus());
}
}
}
public class YoutubeApi {
    public static String youtubechannelid(String channelname)
    {
        Http http =new Http();
        HttpRequest res=new HttpRequest();
        res.setEndpoint('https://www.googleapis.com/youtube/v3');
        res.setMethod('GET');
        HttpResponse resp=http.send(res);
        if(resp.getStatusCode()==200)
        {
            Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(res.getBody());
            List<object>result=(List<Object>)jsonbody.get('ChannelId');
            system.debug( result);
            return result;
        }
        
    }

}
public class oppsoftrigger1
{
public static void triggeronoppsandcontact(List<Opportunity>opp)
{
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE CloseDate=TODAY AND Id IN:Trigger.new]);
for(Opportunity o:opp)
{
Contact c=new Contact();
c.FirstName='neha';
c.LastName='mehra';
c.AccountId=o.AccountId;
conlist.add(c);
}
insert conlist;
}
}
Then i make a trigger on opportunity
trigger oppsontrigger on Opportunity (after insert) {
oppsoftrigger.triggeronoppandcontact(Trigger.new);
}
trigger Opps_trigger1 on Opportunity (after insert) {
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE AccountID IN:Trigger.new]);
for(Opportunity o:Trigger.new)
{
c.AccountID=o.AccountID;
c.FirstName='aryan';
c.LastName='jha';
conlist.add(c);
}
insert conlist;
}
trigger AccountAddressTrigger on Account(Before insert,before update) {
 for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }
}