• Devendra Hirulkar 3
  • NEWBIE
  • 65 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 29
    Replies
hello 
i have write a test class class that shows the following error 

(System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, offer: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddCSR: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.AddCSR: line 4, column 1: []

Trigger.offer: line 10, column 1: [])

what is problem with my test class
here i show my trigger and test class

trigger:-
trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

the above is my trigger
and
the below is my test class
test class:-
@istest
public class updateaccount 
{
     static testMethod void verifyProductUpdation()
    {
       
        Account a=new Account(Name='ABC');
        insert a;
        
        a=[Select Id,Name from Account where Id =:a.Id];
        System.assertEquals(null, a.Product_Name__c);
        
        Product2 p=new Product2(Name='XYZ');
        insert p;
        test.startTest();
        Subsc__c sub=new Subsc__c(Name='CBZ',Company_Name__c=a.Id,Product__c=p.Id);
        insert sub;
        a.Product_Name__c=p.Id;
        update a;
        a=[Select Id,Product_Name__c from Account where Id=:a.Id];
        
        System.assertEquals(p.Id,a.Product_Name__c);
        test.stopTest();
    }   
}
thanks
Devendra 
hello 
i have write a test class class that shows the following error 

(System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, offer: execution of AfterInsert)
what is problem with my test class
here i show my trigger and test class

trigger:-
trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

the above is my trigger
and
the below is my test class
test class:-
@istest
public class updateaccount 
{
     static testMethod void verifyProductUpdation()
    {
       
        Account a=new Account(Name='ABC');
        insert a;
        
        a=[Select Id,Name from Account where Id =:a.Id];
        System.assertEquals(null, a.Product_Name__c);
        
        Product2 p=new Product2(Name='XYZ');
        insert p;
        test.startTest();
        Subsc__c sub=new Subsc__c(Name='CBZ',Company_Name__c=a.Id,Product__c=p.Id);
        insert sub;
        a.Product_Name__c=p.Id;
        update a;
        a=[Select Id,Product_Name__c from Account where Id=:a.Id];
        
        System.assertEquals(p.Id,a.Product_Name__c);
        test.stopTest();
    }   
}
thanks
Devendra 
 
Hello
the following is my trigger
and i have no idea to how to write test class so please help me sir

trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}
please ans as soon possible
thanks 
devendra
Hello 
i am new in the salesforce and i have dont no how to write a test class so please help me and know how to write a test class of the following trigger 
thanks
the following is my trigger


trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}
hello friends,
i have two object sub and account when i add data on sub  object like (product name which is a filed in sub) it automatically added that data to account in field product name  but when i added data on same account it replace the previous one and inserted the new one but i want both data previous and new inserted so how can i do this 
like first product name is gold and when i add another product name like silver then in my work it display like  both gold, siver that i have inserted old one and new 
 here is my trigger 


trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

please let me know as soon as possible
thanks
deoo
thanks
devendra
hello
i have two object sub and account when i add data on sub  like (product name is a filed in sub) it automatically added to account in field product name  but when i added data on same account it replace the priveus one so how can i add multiple data in it
like first product name is gold and when i add another product name like silver then it display like  gold, siver,... etc
 here is my below trigger 
thanks
devendra


trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}
Hello friends
i have created an trigger that  copy one obj to another 
but i have  three record type like recordtype1, recordtype2, recordtype3  when i selected recordtype3 only the case the trigger have been fire otherwise it will not fire 
so what i needed, to do this

following is my trigger

trigger copypro  on Subsc__c  (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
  set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Product__c     != null)
    {
       cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
     }
  }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        
        for(Subsc__c s : trigger.new)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product_Name__c =pro;
                update Acc.values();
            }
        }
    }
   
}
Hello friends
i have created an trigger that  copy one obj to another 
but before copy it has three record type like recordtype1, recordtype2, recordtype3  when i selected recordtype3 only the case it can run 
so what i needed to do this

following is my trigger

trigger copypro  on Subsc__c  (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
  set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Product__c     != null)
    {
       cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
     }
  }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        
        for(Subsc__c s : trigger.new)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product_Name__c =pro;
                update Acc.values();
            }
        }
    }
   
}

   
Hi friends,
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
the below is my trigger


trigger copypro on Subsc__c (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__r.Name  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);


  for (Subsc__c sub : Trigger.new)
  {
     Account ac = Acc.get(sub.Company_Name__c);
    ac.Product_Name__c= sub.Product__r.Name;
  }

  update Acc.values();
}
Hi friends,
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
the below is my trigger


trigger copypro on Subsc__c (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);

  for (Subsc__c sub : Trigger.new)
  {
     Account ac = Acc.get(sub.Company_Name__c);
     ac.Product_Name__c=sub.Product__c;
  }

  update Acc.values();
}
thanks..
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
by using formula or some changes in my trigger
(i want name instated of id)
For example, the Owner of an Opportunity record is Jim Smith.  When I use the formula (trigger)to pass his name to the associated new object, I only get his User ID. 
 
Hi all 
in my below querry the following error shows 
ERROR at Row:1:Column:68
Didn't understand relationship 'Subscriptions__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

in the below qureey
(SELECT id, Product_Name__c,(SELECT ID, membership_type_del__c FROM Subscriptions__r) FROM Account)
thanks 
please replies me fast friends
hello friends in the following trigger the error show
(Didn't understand relationship 'Subscription__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.)
the product field is lookup to the subscription but still it show the error 

trigger copyproductnametoaccount on Subscription__c (after insert,after update) //You want it on update too, right?
{
  Map<ID, Account> parentpname = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subscription__c childObj : Trigger.new)
  {
    listIds.add(childObj.membership_type_del__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
    parentpname = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID, membership_type_del__c FROM Subscription__r) FROM Account WHERE ID IN :listIds]);

  for (Subscription__c sub : Trigger.new)
  {
     Account myParentpname = parentpname.get(sub.membership_type_del__c);
     myParentpname.Product_Name__c = Decimal.valueOf(sub.membership_type_del__c);
  }
    
  update parentpname.values();
}
trigger to copy parent obj to child
hello friends i want trigger to copy parent obj to child only when the field type us user group
i have 3 obj  account , product and subscrations
by this trigger in subscration there is 3 field type like elearning , digital learning and user group  by this trigger if we select field type user group then only it   match account  name if match then put product  name into account
here account and product are lookup into subscration  when we chose  user group field type in subscration it match account  name like account name is devendra then  when we put  product name in substraction  then it automatcally put that product name into account
thanks
devendra
hello friends
here i have write a trigger that copy data from parent obj to child when name is match
but in my trigger the following error shows (Didn't understand relationship 'Subscriptions__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.) i dont undestand the problem
so plese help me 
here is my trigger 

trigger copyproductnametoaccount on Subscription__c (after insert,after update) //You want it on update too, right?
{
  Map<ID, Account> parentpname = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subscription__c childObj : Trigger.new)
  {
    listIds.add(childObj.membership_type__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentpname = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID, membership_type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);

  for (Subscription__c sub : Trigger.new)
  {
     Account myParentpname = parentpname.get(sub.membership_type__c);
     myParentpname.Product_Name__c = Decimal.valueOf(sub.membership_type__c);
  }
    
  update parentpname.values();
}

  
 
in my test class the (System.AssertException: Assertion Failed: Expected: 2.5, Actual: 0)error shows what is proble 
the below is my test class


@istest
public class myclass 
{
     static testMethod void veriflyStudentupdation()
    {
        Student__c student = new Student__c(Name='Sam',Roll_No__c=2.5,Address__c='silod');
        {
            insert student;

            class__c newClass = new class__c(student__c = student.Id, Roll_No__c= '2');

            test.startTest();

            insert newClass;
            System.debug('Test Started.,..');

            test.stopTest();
            System.debug('Test Completed.,..');

            student__c upd_student = [Select Id,Roll_No__c  from student__c where id = :student.Id];
            system.assertEquals(2.5, upd_student.Roll_No__c );
        }    

    }   
}
hellow all
i dont no how to write a test class of trigger please help me and tell the test class of below trigger
thankss
here is my trigger 

trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}
hellow friends,
i want test class of the below trigger i am new in the apex word so please tell me the test class 

trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}

this is my trigger 
thanks 
deoo
hi all
this is my trigger i dont no how to write test class for this trigger
please help me to know how to do this
trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}
trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];
Hi all
 a am trying to create a trigger that copy chield obj to parent .  but  i keep getting the following error: compile error :unexpected token: ':' at line no 8
here is my code
// SOQL to get the exact account with matching name as child

 Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here is error)
 par.Roll_No__c = con.Roll_No__c
 update con; 
    
}
hello 
i have write a test class class that shows the following error 

(System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, offer: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddCSR: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.AddCSR: line 4, column 1: []

Trigger.offer: line 10, column 1: [])

what is problem with my test class
here i show my trigger and test class

trigger:-
trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

the above is my trigger
and
the below is my test class
test class:-
@istest
public class updateaccount 
{
     static testMethod void verifyProductUpdation()
    {
       
        Account a=new Account(Name='ABC');
        insert a;
        
        a=[Select Id,Name from Account where Id =:a.Id];
        System.assertEquals(null, a.Product_Name__c);
        
        Product2 p=new Product2(Name='XYZ');
        insert p;
        test.startTest();
        Subsc__c sub=new Subsc__c(Name='CBZ',Company_Name__c=a.Id,Product__c=p.Id);
        insert sub;
        a.Product_Name__c=p.Id;
        update a;
        a=[Select Id,Product_Name__c from Account where Id=:a.Id];
        
        System.assertEquals(p.Id,a.Product_Name__c);
        test.stopTest();
    }   
}
thanks
Devendra 
Hello
the following is my trigger
and i have no idea to how to write test class so please help me sir

trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}
please ans as soon possible
thanks 
devendra
Hello friends
i have created an trigger that  copy one obj to another 
but i have  three record type like recordtype1, recordtype2, recordtype3  when i selected recordtype3 only the case the trigger have been fire otherwise it will not fire 
so what i needed, to do this

following is my trigger

trigger copypro  on Subsc__c  (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
  set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Product__c     != null)
    {
       cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
     }
  }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        
        for(Subsc__c s : trigger.new)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product_Name__c =pro;
                update Acc.values();
            }
        }
    }
   
}
Hi friends,
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
the below is my trigger


trigger copypro on Subsc__c (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__r.Name  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);


  for (Subsc__c sub : Trigger.new)
  {
     Account ac = Acc.get(sub.Company_Name__c);
    ac.Product_Name__c= sub.Product__r.Name;
  }

  update Acc.values();
}
Hi friends,
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
the below is my trigger


trigger copypro on Subsc__c (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
  }

  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called Quotes__r (not Quote__r) but check
  //You only need to select the child quotes if you are going to do something for example checking whether the quote in the trigger is the latest
  Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c  FROM Subscs__r) FROM Account WHERE ID IN :listIds]);

  for (Subsc__c sub : Trigger.new)
  {
     Account ac = Acc.get(sub.Company_Name__c);
     ac.Product_Name__c=sub.Product__c;
  }

  update Acc.values();
}
thanks..
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
by using formula or some changes in my trigger
(i want name instated of id)
For example, the Owner of an Opportunity record is Jim Smith.  When I use the formula (trigger)to pass his name to the associated new object, I only get his User ID. 
 
Hi all 
in my below querry the following error shows 
ERROR at Row:1:Column:68
Didn't understand relationship 'Subscriptions__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

in the below qureey
(SELECT id, Product_Name__c,(SELECT ID, membership_type_del__c FROM Subscriptions__r) FROM Account)
thanks 
please replies me fast friends
hello friends
here i have write a trigger that copy data from parent obj to child when name is match
but in my trigger the following error shows (Didn't understand relationship 'Subscriptions__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.) i dont undestand the problem
so plese help me 
here is my trigger 

trigger copyproductnametoaccount on Subscription__c (after insert,after update) //You want it on update too, right?
{
  Map<ID, Account> parentpname = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subscription__c childObj : Trigger.new)
  {
    listIds.add(childObj.membership_type__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentpname = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID, membership_type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);

  for (Subscription__c sub : Trigger.new)
  {
     Account myParentpname = parentpname.get(sub.membership_type__c);
     myParentpname.Product_Name__c = Decimal.valueOf(sub.membership_type__c);
  }
    
  update parentpname.values();
}

  
 
in my test class the (System.AssertException: Assertion Failed: Expected: 2.5, Actual: 0)error shows what is proble 
the below is my test class


@istest
public class myclass 
{
     static testMethod void veriflyStudentupdation()
    {
        Student__c student = new Student__c(Name='Sam',Roll_No__c=2.5,Address__c='silod');
        {
            insert student;

            class__c newClass = new class__c(student__c = student.Id, Roll_No__c= '2');

            test.startTest();

            insert newClass;
            System.debug('Test Started.,..');

            test.stopTest();
            System.debug('Test Completed.,..');

            student__c upd_student = [Select Id,Roll_No__c  from student__c where id = :student.Id];
            system.assertEquals(2.5, upd_student.Roll_No__c );
        }    

    }   
}
hellow all
i dont no how to write a test class of trigger please help me and tell the test class of below trigger
thankss
here is my trigger 

trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}
I am using professional edition.So,I want to know whenever i choose account name in lookup field in contact object the related custom fields in accounts have to copied to the contact custom fields using custom button.
trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];
Hi all
 a am trying to create a trigger that copy chield obj to parent .  but  i keep getting the following error: compile error :unexpected token: ':' at line no 8
here is my code
// SOQL to get the exact account with matching name as child

 Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here is error)
 par.Roll_No__c = con.Roll_No__c
 update con; 
    
}
i have two object  child(class) and parent(student) 
 
student         class
----------------------------
name           name
address        student(lookup)
rollno          rollno
------------------------------
in above to obj if student name and class name will match  then it copy rollno from class and put into student 
please tell me how to get this 
thanks,
devendra
trigger to copy child field data to parent field data 
like i have copy data from  student(child) to class (parent) but by matching the name of both child and parent 
if the name of the both child and parent are match then only save the data like if the name of both child and parent are match then when we save rollno on student it compare name if match then it automticlly stored on class
 thanks