• sruthi.458
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies

Hi friends,

 

can any one help me how to write a test code for webservices.

 

for example,

 

global class CallYahooQuotes
{
@future(callout=true)
public static void getQuotes()
{ //for our simple example we are going to just update the quotes on one Account
Account acct = [select id, TickerSymbol, stock_price__c from account where name = 'Salesforce.com'];

//where f stands for the fields to be displayed (in this case: s - symbol; l1 - last price; c1 - change; d1 = last date)
// String url = 'http://quote.yahoo.com/d/quotes.csv?s='+acct.TickerSymbol+'&f=sl1c1d1&e=.csv';

String url = 'http://download.finance.yahoo.com/d/quotes.csv?s='+acct.TickerSymbol+'&f=l1&e=.csv';

Http h = new Http();

HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');

HttpResponse res = h.send(req);

//omitting error handling for example
acct.stock_price__c = decimal.valueOf(res.getBody().trim());
update acct;
}

}

 

Thanks,

Srikanth

hi    
 i write a test code for batch apex for deleteing multiple records for at a time
@istest
public class testc1

 public static testmethod void c11()
 {
   integer bc=[select count() from lead where company='ibm'];
    if(bc>0)
    {
       delete d= new delete('select id from lead where company=ibm');
       id batchinstanceid=database.executebatch(d,10);
     }
  integer ac=[select count() from lead where company='ibm'];    
   system.assertequals(0,ac);

   }
}
 
  i have a doubt an where to mention delete
can u fix it a solution

 

Regards,
Srikanth

@istest
public class trg4
{
public static testmethod void testtrg4()
{
account a=new account();
a.name='mohan';
a.billingcity='pune';
a.phone='09885298297';
insert a;
integer cnt=[select count() from account where name=:a.name and billingcity=:a.billingcity];
delete a;

a.name='mohan';
a.phone='09700085852';
a.billingcity='pune';
insert a;
system.assertequals(cnt,1);
}
}

Hi friends,

can any one post test code for the below trigger.


trigger trg5 on Opportunity (before insert) 

{
  for(opportunity o:trigger.new)
  {
    if(o.amount>2500000)
     o.adderror('not inserted');
     }
}

Regards,
Srikanth

Hi Friends,

I write a code for trigger and it has no errors also it works successfully but code coverage is 0%.

Can any one suggest for a solution.



trigger email on Lead (after insert) 
{
  string leadId = trigger.new[0].id;
  list<lead > lstlead =[select id,email from lead where id=:leadId];
  string leademail =lstlead[0].email;

     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses(new String[] { leademail  });
    mail.setSubject('Document Email Demo');
    mail.setHtmlBody('Here is the email you requested');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  
}

Regards,
Srikanth

Hi Friends,

 

 If iam trying to write a test code for Apex class it will not save because of the class name already exists..

      Example:

public class myclass
{
    account a;
    public account getAcc() 
    {
     a=[select id,name from account where id=:apexpages.currentpage().getparameters().get('id')];
        return a;
    }
    public PageReference del() 
    {
       delete a;
        return null;
    }


    public PageReference save()
     {
        return null;
    }

 

 

 

How can i write a test code for the above Apex class....?

 

 

Regards,

Srikanth

Hi friends,

 

can any one help me how to write a test code for webservices.

 

for example,

 

global class CallYahooQuotes
{
@future(callout=true)
public static void getQuotes()
{ //for our simple example we are going to just update the quotes on one Account
Account acct = [select id, TickerSymbol, stock_price__c from account where name = 'Salesforce.com'];

//where f stands for the fields to be displayed (in this case: s - symbol; l1 - last price; c1 - change; d1 = last date)
// String url = 'http://quote.yahoo.com/d/quotes.csv?s='+acct.TickerSymbol+'&f=sl1c1d1&e=.csv';

String url = 'http://download.finance.yahoo.com/d/quotes.csv?s='+acct.TickerSymbol+'&f=l1&e=.csv';

Http h = new Http();

HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');

HttpResponse res = h.send(req);

//omitting error handling for example
acct.stock_price__c = decimal.valueOf(res.getBody().trim());
update acct;
}

}

 

Thanks,

Srikanth

hi    
 i write a test code for batch apex for deleteing multiple records for at a time
@istest
public class testc1

 public static testmethod void c11()
 {
   integer bc=[select count() from lead where company='ibm'];
    if(bc>0)
    {
       delete d= new delete('select id from lead where company=ibm');
       id batchinstanceid=database.executebatch(d,10);
     }
  integer ac=[select count() from lead where company='ibm'];    
   system.assertequals(0,ac);

   }
}
 
  i have a doubt an where to mention delete
can u fix it a solution

 

Regards,
Srikanth

@istest
public class trg4
{
public static testmethod void testtrg4()
{
account a=new account();
a.name='mohan';
a.billingcity='pune';
a.phone='09885298297';
insert a;
integer cnt=[select count() from account where name=:a.name and billingcity=:a.billingcity];
delete a;

a.name='mohan';
a.phone='09700085852';
a.billingcity='pune';
insert a;
system.assertequals(cnt,1);
}
}

Hi Friends,

I write a code for trigger and it has no errors also it works successfully but code coverage is 0%.

Can any one suggest for a solution.



trigger email on Lead (after insert) 
{
  string leadId = trigger.new[0].id;
  list<lead > lstlead =[select id,email from lead where id=:leadId];
  string leademail =lstlead[0].email;

     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses(new String[] { leademail  });
    mail.setSubject('Document Email Demo');
    mail.setHtmlBody('Here is the email you requested');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  
}

Regards,
Srikanth

Hi Friends,

 

 If iam trying to write a test code for Apex class it will not save because of the class name already exists..

      Example:

public class myclass
{
    account a;
    public account getAcc() 
    {
     a=[select id,name from account where id=:apexpages.currentpage().getparameters().get('id')];
        return a;
    }
    public PageReference del() 
    {
       delete a;
        return null;
    }


    public PageReference save()
     {
        return null;
    }

 

 

 

How can i write a test code for the above Apex class....?

 

 

Regards,

Srikanth

I am new to this so I assume this is a pretty simple question. I am trying to develop an e-mail alert that is sent when an Attachment is added to an Account. I am trying to get the Account name in the email. When I receive the email the subject just says: "Attachment Added: name". Attachment and Account are related through parentid, but I am having trouble returning account fields on an Attachment trigger. What am I doing wrong?  

 

 

trigger Send_email on Attachment (after insert) {
Attachment attach = trigger.new[0];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ja@example.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('support@example.com');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('Attachment Added : ' + account.name);
mail.setPlainTextBody('work please');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}