• hanifa fatima
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies

I want to retrieve the code from the ligtningcomponent into node using JSforce. Is there any query for metadata to retrieve it? 

conn.sobject("AuraDefinitionBundle").select('*').where({DeveloperName : object})
          .execute(function(err, records) {
            console.log(records);
This is how i tried but i need the code retrieval from controller or the component too.

trigger DeletingChildRecor on Account (Before delete) {
    Set<Id> s=new Set<Id>();
    for(Account a:Trigger.old)
    {
    System.debug('Adding ids');
        s.add(a.id);
    }
    list<contact> ls=[select id,name from contact where contact.accountid=:s];
    system.debug('About to Enter');
    if(Trigger.isDelete)
    {
    system.debug('Entered');
      if(ls.size()==1)
      {
          system.debug('Cant DELETE');
      }
          
  }
}

Here the trigger should fire when we delete the last child record of an account, it should throw an error saying that the last child cannot be be deleted.
trigger CreationOfContact on Account (after insert,after Update) {
Map<Id,Decimal> mp=new Map<Id,Decimal>();
list<Contact> lst=new List<Contact>();
  for(Account a:Trigger.New)
  { 
   mp.put(a.id,a.Number_Of_Contacts__c);
  }
   if(Trigger.isInsert && Trigger.isAfter)
   {
    if(mp.size()>0 && mp!=null)
    {
     for(Id a:mp.keyset())
     {
      for(Integer i=1;i<=mp.get(a);i++)
      {
        Contact c=new Contact();
        c.lastname='Test'+i;
        c.accountid=a;
        lst.add(c);
      }
     }
    }
   }
   insert lst;
   if(Trigger.isUpdate && Trigger.isAfter)
   {
    
   for(Account a:Trigger.new)
   {
    Decimal a1=trigger.oldmap.get(a.id).Number_Of_Contacts__c;
    Decimal a2=trigger.newMap.get(a.id).Number_Of_Contacts__c;
    Decimal a3=0;
    if(a2>a1)
    {
      a3=a2-a1;
      for(Integer i=1;i<=a3;i++)
      {
        Contact c=new Contact();
        c.lastname='Update' +i;
        c.AccountId=a.id;
        lst.add(c);
      }
     }    
    }
      insert lst;
   }
   
}


In this trigger i have created a custom field called no.of.contacts on account object, i've the following scenario:
1. When a new account is created and the that field is populated with (say 2) it should create 2 new contacts.

2. When i edit the that field ( say to 5 now before it was 2 ) so the difference of both is now 3, so it should 3 more contacts.

3. when i edit that field to (say to 4 now earlier the new updated value is 5) so the difference is 1 here , therefore 1contact should be deleted.


So, the code i've written works well upto 2nd scenario, the only problem i;m facing now is at 3rd scenario.

Could someone help me out?

trigger UpdateContactOnAcc2 on Account (after update) {


  for(Account a :Trigger.new)
  {
     list <contact> con = [select lastname, LeadSource  from contact where contact.accountid=:a.id];

     if(trigger.isUpdate)
      {

          
           for(Contact c: con)
           {
             c.LeadSource='Web';
             c.accountid=a.id;
             c.OtherPhone=a.Phone;
           update c;
           } 
      } 
 

  }
  }
//We Update the child record for that account whenever any field (say phone is changed) the same changes should be reflected in the child record
  //updating child record without repeating the query in the loop and running the query only once


This is the Test Class i've written
@isTest
public class TestClassUpdateAcc {
 static testmethod void updateAcc()
   {
     Account acc = new Account();
      acc.Name = 'Loader';
       insert acc;
       acc=[select name,phone from account];
       acc.Phone='98765';
       update acc;
      // acc=[select name, phone from account];
       // System.assertEquals('555', acc.Phone);

       
      Contact con = new Contact();
      con.LastName = 'xxxx';
      con.AccountId =acc.Id;
      con.OtherPhone=acc.Phone;
       con.LeadSource='email';
      insert con;
        con=[select LastName, AccountID,otherphone from contact];
        con.LeadSource='web';
         update con;
     //   System.assertEquals('Web', con.LeadSource);
       
       
 
               
   }
}

 
trigger UpdateType on Account (before insert,before update,after insert) {
if(trigger.isInsert && trigger.isBefore)
{
for(Account a:trigger.new)
{
if(a.industry=='education')
{
a.addError('we dont deal with education industry');
}
}
}
if(trigger.isUpdate)
{
for(Account a:trigger.new)
{
if(a.Type=='Prospect')
{
a.Type='Other';
}
}
}
}
@isTest
public class UpdateTypeTest {
static testmethod void accUpdate()
{
   Account acc= new Account( Name='Example', Industry='Education');
    insert acc;
    acc=[select name, industry, type from account where type=:acc.Type];
    System.assertEquals('Other', acc.Type);
    update acc;
   
    
}
}

Test class for the Trigger

Here the trigger fires whenever we give the type on account as prospect it would update it to 'Other'

My test class is covering only 60% of the code , somehow it is not covering the updated part. Can someone help me out?

trigger CreationOfContact on Account (after insert,after Update) {
Map<Id,Decimal> mp=new Map<Id,Decimal>();
list<Contact> lst=new List<Contact>();
  for(Account a:Trigger.New)
  { 
   mp.put(a.id,a.Number_Of_Contacts__c);
  }
   if(Trigger.isInsert && Trigger.isAfter)
   {
    if(mp.size()>0 && mp!=null)
    {
     for(Id a:mp.keyset())
     {
      for(Integer i=1;i<=mp.get(a);i++)
      {
        Contact c=new Contact();
        c.lastname='Test'+i;
        c.accountid=a;
        lst.add(c);
      }
     }
    }
   }
   insert lst;
   if(Trigger.isUpdate && Trigger.isAfter)
   {
    
   for(Account a:Trigger.new)
   {
    Decimal a1=trigger.oldmap.get(a.id).Number_Of_Contacts__c;
    Decimal a2=trigger.newMap.get(a.id).Number_Of_Contacts__c;
    Decimal a3=0;
    if(a2>a1)
    {
      a3=a2-a1;
      for(Integer i=1;i<=a3;i++)
      {
        Contact c=new Contact();
        c.lastname='Update' +i;
        c.AccountId=a.id;
        lst.add(c);
      }
     }    
    }
      insert lst;
   }
   
}


In this trigger i have created a custom field called no.of.contacts on account object, i've the following scenario:
1. When a new account is created and the that field is populated with (say 2) it should create 2 new contacts.

2. When i edit the that field ( say to 5 now before it was 2 ) so the difference of both is now 3, so it should 3 more contacts.

3. when i edit that field to (say to 4 now earlier the new updated value is 5) so the difference is 1 here , therefore 1contact should be deleted.


So, the code i've written works well upto 2nd scenario, the only problem i;m facing now is at 3rd scenario.

Could someone help me out?

trigger CreationOfContact on Account (after insert,after Update) {
Map<Id,Decimal> mp=new Map<Id,Decimal>();
list<Contact> lst=new List<Contact>();
  for(Account a:Trigger.New)
  { 
   mp.put(a.id,a.Number_Of_Contacts__c);
  }
   if(Trigger.isInsert && Trigger.isAfter)
   {
    if(mp.size()>0 && mp!=null)
    {
     for(Id a:mp.keyset())
     {
      for(Integer i=1;i<=mp.get(a);i++)
      {
        Contact c=new Contact();
        c.lastname='Test'+i;
        c.accountid=a;
        lst.add(c);
      }
     }
    }
   }
   insert lst;
   if(Trigger.isUpdate && Trigger.isAfter)
   {
    
   for(Account a:Trigger.new)
   {
    Decimal a1=trigger.oldmap.get(a.id).Number_Of_Contacts__c;
    Decimal a2=trigger.newMap.get(a.id).Number_Of_Contacts__c;
    Decimal a3=0;
    if(a2>a1)
    {
      a3=a2-a1;
      for(Integer i=1;i<=a3;i++)
      {
        Contact c=new Contact();
        c.lastname='Update' +i;
        c.AccountId=a.id;
        lst.add(c);
      }
     }    
    }
      insert lst;
   }
   
}


In this trigger i have created a custom field called no.of.contacts on account object, i've the following scenario:
1. When a new account is created and the that field is populated with (say 2) it should create 2 new contacts.

2. When i edit the that field ( say to 5 now before it was 2 ) so the difference of both is now 3, so it should 3 more contacts.

3. when i edit that field to (say to 4 now earlier the new updated value is 5) so the difference is 1 here , therefore 1contact should be deleted.


So, the code i've written works well upto 2nd scenario, the only problem i;m facing now is at 3rd scenario.

Could someone help me out?