• Yuvaraj mayilsamy 9
  • NEWBIE
  • 55 Points
  • Member since 2018

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 17
    Replies
I need to create a test for it can anyone help provide the coding for the test please? (possibly with directions on how to get the process done)?


trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

update listaccount;



}
Hi, 

I have custom object in related list in Opportunity.

In Opportunity, I have picklict field named Region with values INDIA, UK, US

And depend on the region value, I want to show the value in formula field in related list.

For rg : If region is INDIA, the formmula field say State = Maharashtra

How should I do that?
Hi, 

I have two objects employee__c and department__c where employee__c is the child object for department__c. My requirement is if a child record is added then the description__c field in master record should get updated. Below  is my code but it is showing Error: Compile Error: IN operator must be used with an iterable expression at line 3 column 36. Any help is appreciated.
 
trigger descriptionupdate on Employee__c (after insert) {
map<id, employee__c> myid = new map<id, employee__C>([select id, department__r.id from employee__c where id in:trigger.new]);
list<department__c> depstoupdate = [select name, description__c from department__C where id in:myid];
for(department__c d : depstoupdate){
d.description__c = 'The last employee added to this department is on ' +system.today();
}
update depstoupdate;
}

 
to delete contact records  through soql query
Hi ,
can we Update the Records From parent to child & also  from child to parent  (viceversa ) through trigger .
I have a requirement where i have 10-15 Fields In parent Whose values i need to update in child fields &  fields with Same values  i have in child ,If I update any child field values from Child that should Update the values in parent. How We can do this through Trigger when record is Inserted & also While Updated ?  
THE CODE USED

trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

The ITEST CODE

@istest
02public class testnumberofcontacts {
03    @istest static void checknumbers(){
04        test.starttest();
05        account testaccount = new account(name = 'Test account');
06        insert testaccount;
07        contact testcontact = new contact(lastname = 'Samplename', accountid = testaccount.Id);
08        insert testcontact;
09        test.stopTest();
10        list<account> queriedaccount = [select name, number_of_contacts__C from account where id =: testaccount.Id];
11        decimal resultcount;
12        for(account a: queriedaccount){
13            resultcount = a.Number_of_contacts__c;
14        }
15        system.assertEquals(1, resultcount);
16    }
17 
18}

THE 7! FAILURES

CMBatchCampaignStatsTesttest_LinkedCampaignsSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns: line 58, column 1
CMBatchCampaignStatsTesttest_LinkedCampaigns_doRun_UpdateOnSystem.AssertException: Assertion Failed: Expected: 25, Actual: null 
Stack Trace: Class.wbsendit.CMBatchCampaignStatsTest.test_LinkedCampaigns_doRun_UpdateOn: line 93, column 1
CMBatchCampaignTesttest_addMissingMemberStatusesSystem.AssertException: Assertion Failed: Expected: 3, Actual: 1 
Stack Trace: Class.wbsendit.CMBatchCampaignTest.test_addMissingMemberStatuses: line 212, column 1
DisconnectControllerTesttest_Savewbsendit.fflib_SecurityUtils.CrudException: You do not have permission to update Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsUpdateable: line 413, column 1 Class.wbsendit.fflib_SecurityUtils: line 272, column 1 Class.wbsendit.DisconnectController.disconnect: line 26, column 1 Class.wbsendit.DisconnectControllerTest.test_Save: line 32, column 1
LinkCampaignControllerTesttest_autoCreateSalesforceCampaignswbsendit.fflib_SecurityUtils.CrudException: You do not have permission to insert Campaign. See: http://support.beaufort12.com/customer/en/portal/articles/2819881 
Stack Trace: Class.wbsendit.fflib_SecurityUtils.checkObjectIsInsertable: line 388, column 1 Class.wbsendit.fflib_SecurityUtils: line 137, column 1 Class.wbsendit.LinkCampaignController.autoCreateSalesforceCampaigns: line 191, column 1 Class.wbsendit.LinkCampaignControllerTest.test_autoCreateSalesforceCampaigns: line 78, column 1
LinkCampaignControllerTesttest_SaveSystem.AssertException: Assertion Failed: Same value: null 
Stack Trace: Class.wbsendit.LinkCampaignControllerTest.test_Save: line 38, column 1
ReportToListBatchTesttest_doReportToBatchSystem.LimitException: reports:Too many query rows: 50001 
Stack Trace: External entry point Class.wbsendit.ReportToListBatch.getNumberOfRows: line 469, column 1 Class.wbsendit.ReportToListBatch.doStart: line 142, column 1 Class.wbsendit.ReportToListBatch.start: line 48, column 1

User-added image
Hello
I am new to writing test class. I need help in writing test class for the following code.
scenairo: when I create a new account from UI, a nee opportunity record gets created under the account.
public class CreateNewOpportunity
{
   public List<Opportunity> oppList=new List<Opportunity>();
   
   public void CreateOpportunity(List<Account> accList)
   {
     for(Account a:accList)
     {
       Opportunity o = new Opportunity();
       o.AccountID=a.ID;
       
       o.Name=a.Name;
       o.CloseDate=System.Today().addDays(3);
       
       o.StageName='Prospecting';
       
       oppList.add(o);
     }
     
     if (oppList.size() > 0)
         Database.Insert(oppList);
   }
}

trigger trg_createnewoppor on Account (after Insert,after update)
{
  if ((Trigger.isInsert) || (Trigger.IsBefore))
  {
    CreateNewOpportunity o = new CreateNewOpportunity();
    o.CreateOpportunity(Trigger.New);
  }
}


Thanks
smita
I need to create a test for it can anyone help provide the coding for the test please? (possibly with directions on how to get the process done)?


trigger  NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();

list<account> listaccount = new list<account>();
for(contact con : trigger.new){

setid.add(con.accountid);
}

For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();

ac1.id=acc.id;

ac1.Number_of_Contacts__c= acc.contacts.size();

listaccount.add(ac1);
}

update listaccount;



}
Hi, 
 I want to create a apex class with the below input an output.. am new to SF please help.



Input 
===== 
Field1|Field2 
AAA|1,2 
BBB|1,2,3 
CCC|1,2,3,4 
DDD|1,2,3,4,5 


Output 
====== 
AAA|1 
AAA|2 
BBB|1 
BBB|2 
BBB|3 
CCC|1 
CCC|2 
CCC|3 
CCC|4 
DDD|1 
DDD|2 
DDD|3 
DDD|4 
DDD|5 
For this Do I need to use the tooling api? or without api's can I achiev.
Found one refernce link :http://developer.force.com/cookbook/recipe/automated-unit-test-execution

please suggest me, what is the correct approch.

Thanks in advance!
Suppose we have group of checkboxs if
                  ( one check box is checked) {
                                             correction required
}
else 
{
None
}
Hello ,

How can I change the below veiw?
Thank you!
User-added image
The requirement is like ECom Finance Advisor profile user do not have permission to close the cases and still if he trying to close the case, it should give error. For this i have written a validation rule like below, but it is not working.

AND(Owner:User.Profile.Name="ECom Finance Advisor", 
ECom_Quick_Close__c == true)

ECom_Quick_Close__c is checkbox type field and ECom Finance Advisor is name of the profile.
Hi, 

I have custom object in related list in Opportunity.

In Opportunity, I have picklict field named Region with values INDIA, UK, US

And depend on the region value, I want to show the value in formula field in related list.

For rg : If region is INDIA, the formmula field say State = Maharashtra

How should I do that?
Hi, 

I have two objects employee__c and department__c where employee__c is the child object for department__c. My requirement is if a child record is added then the description__c field in master record should get updated. Below  is my code but it is showing Error: Compile Error: IN operator must be used with an iterable expression at line 3 column 36. Any help is appreciated.
 
trigger descriptionupdate on Employee__c (after insert) {
map<id, employee__c> myid = new map<id, employee__C>([select id, department__r.id from employee__c where id in:trigger.new]);
list<department__c> depstoupdate = [select name, description__c from department__C where id in:myid];
for(department__c d : depstoupdate){
d.description__c = 'The last employee added to this department is on ' +system.today();
}
update depstoupdate;
}

 
Hello,

I've never written a trigger before and was wondering if someone can help. All I need is a trigger on the Account object, on update, that will check to see if Tax ID changed. If this is true, then update the Comments field with something like "Tax ID was last updated on" & Today(). The pseudocode would be something like this:

Trigger TaxIdChanged on Account (On Update)
If ISCHANGED(Tax_id__c) = True
    Comments = "Tax ID was last updated on" & Today()
End

It is important to know that Tax_Id__c is an encrypted field and this is why I'm having to try to create a trigger to do this since I believe is the only way to look at the contents of an ecrypted field. I've tried doing this via a workflow rule or process builder, and unfortunately was not able to do it becuase I'm dealing with an encrupted field.

Thank you so much!!