• Samadhan Sakhale 3
  • NEWBIE
  • 90 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 12
    Questions
  • 21
    Replies
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();
}
can anybody tell me advantages and disavantages of state and country picklist fields salesforce..?
hi all,

i am trying to set workflow on email event for sending all the information about campign for eg.member,avtivities etc but it is not working properly
so can anyone please help me to create workflow?
and 
if it is not possible then tell me why?

Best Regards,
Sam
Hi,

i'm new to batchable class someone help me to find all contacts which does not have account in salesforce and how to send email to that contact account mail-ID
Hi All,
I’m new in salesforce but now I can write triggers but in salesforce forum I read that all logic should be in apex class so anyone help me improve my trigger? And how to call that apex in Trigger by passing trigger.new argument to that apex Class?
My Trigger is…
 
trigger UpdateprdctonAcc on Subscription__c (before insert)
{
                //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
                Id recordTypeId = Schema.SObjectType.Subscription__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();
    List<Subscription__c> subscList = new List<Subscription__c>();
 
    for (Subscription__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }
    String str;
   
    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 (Subscription__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
     
        if(s.Membership_Type__c!= null)
        {
            cObjectID.add(s.Membership_Type__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__c,(SELECT ID,Membership_Type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
       
        for(Subscription__c s : subscList)
        {  
            if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Membership_Type__c).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product__c=pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
}
 
 Regards,
Sam
hi all,
i have written trigger but it gives only 44% code coverage so what can do forn increase it....?

My trigger is

trigger UpdateprdctonAcc on Subscription__c (after insert) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subscription__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();
    List<Subscription__c> subscList = new List<Subscription__c>();

    for (Subscription__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }
    String str;
    
    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 (Subscription__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Membership_Type__c!= null)
        {
            cObjectID.add(s.Membership_Type__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__c,(SELECT ID,Membership_Type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subscription__c s : subscList)
        {   
            if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Membership_Type__c).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product__c=pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
}


and test class for this is....

@istest
public class TestPrdctonacc 
{
    static testMethod void verifyProductUpdation()
    {
     // Set up the Account record.
    Account a = new Account(Name='Test Account' ,SLA__c='Gold', SLAExpirationDate__c=Date.today(),SLASerialNumber__c='jhbfs');
    insert a;
    
    Product2 p=new Product2(Name='Product Name');
    insert p;
    
    test.startTest();
    // Verify that the initial state is as expected.
    a = [SELECT Name,Product__c FROM Account WHERE Id = :a.Id];
    System.assertEquals(null,a.Product__c);

    // Set up the Opportunity record.
    String company=a.Id;
    Subscription__c sub = new Subscription__c(Name='ABC',Company_Name__c=company,Membership_Type__c=p.Id);
    // Cause the Trigger to execute.
    insert sub;
  
     // Verify that the results are as expected.
    a = [SELECT Name, Product__c FROM Account WHERE Id = :a.Id];
    System.assertEquals(null, a.Product__c);
        test.stopTest();
    }   
}

please tell me answer in brief

Thanks,
Sam
Hello,
    I have write one trigger to copy one field to another but my problem is how can this trigger run only if RecordType="User Group"
My Trigger is

trigger copySubtoAcc on Subscription__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 (Subscription__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Membership_Type__c != null)
    {
       cObjectID.add(s.Membership_Type__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(Subscription__c s : trigger.new)
        {
             if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                 String pro= cObjectMap.get(s.Membership_Type__c).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product__c,(SELECT ID,Membership_Type__c  FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product__c =pro;
                update Acc.values();
            }
        }
    }
   
}


Thanks,
Sam
Hi All,
     I am new to SFDC and i have written one trigger but i'm not able to write test class for it someone please tell me how can i write test class  for this trigger my Trigger is

trigger FetchVatvalue on Quote__c (before insert,before update) 
{
    //create reference table for lookup value
    Map<String, Decimal> vatMap = new Map<String, Decimal>();
    //build reference table for VAT rates
    for (VAT__c vat : [SELECT Name,Vat_Rate__c FROM VAT__c])
        vatMap.put(vat.Name, vat.Vat_Rate__c);
    //update Quote__c with VAT rate
    for (Quote__c q : trigger.new)
    {
        Decimal vatRate = vatMap.get(q.Country_Code__c);
        q.VAT_Rate__c = vatRate;
    }
}

this trigger is wrtten for automaticaly fetch value from another object using picklist

thank you,
Sam
Hi All,
   I have a requirement that when i calculate Net Amount=total=vat that after calculation this i have to fetch that formula field in my parent object so how can i fetch that field using Roll up Summary.
Thanks,
Sam
Hi All,
      I have one object which contains two field,i.e. Contry_Code__c & VAT_Rate__c which contains data like
Country Code           VAT Rate
USD                             0.20
IND                              0.19
EURO                           0.15

and i make this two fields on standard object.so how can fetch the VAT Rate  while i select Contry code(It may be Runtime or While Saving Data)
So please help me to solve this assignment.
Regards,
Sam.
Hi,
     I am trying to copy all cities from Student custom object in Address1 custom object into City__c field.all code working properly and code coverage also 100%
but the problem is that after running program cities not copied in Address table and i also trying to check program execution using System.Debug(''); but the statement not printed after executon in log my Code is here


global class CopyStudtoAdr_Batch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
     String query='SELECT ID,City__c FROM Student__c';
     return Database.getQueryLocator(query);
   }
    global void execute(Database.BatchableContext BC, List<Student__c> scope)
    {
      System.debug('Batch Class Started....');
      //List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : scope] ;
      //Set<String> setSturdentIds = new Set<String>();
      List<Address1__c> adrToUpdate = [Select Id,StudentID__c,City__c from Address1__c where StudentID__c in : Scope];

     Map<ID,Student__c> stdMap = new Map<ID,Student__c>(scope) ;
      
       // Loop to copy account Student to Address phone
       for(Address1__c adr : adrToUpdate)
        {
         adr.City__c =  stdMap.get(adr.StudentID__c).City__c ;
         }
       if(adrToUpdate.size() > 0)
       update adrToUpdate;
      }
     global void finish(Database.BatchableContext ctx)
      {}
}

Please check it and tell me Solution

Thanks,
Sam
How to Copy Custom Object Field record (i.e.phone) to Standard Object field.
Reply me.
hi,
     i have to copy one field all records(Which is already Stored)from custom object to Standard object by creating field on standard Object.
Anyone please tell me example of scheduling this type of job.
thanks,
Sam
Hi,

i'm new to batchable class someone help me to find all contacts which does not have account in salesforce and how to send email to that contact account mail-ID
Hi All,
I’m new in salesforce but now I can write triggers but in salesforce forum I read that all logic should be in apex class so anyone help me improve my trigger? And how to call that apex in Trigger by passing trigger.new argument to that apex Class?
My Trigger is…
 
trigger UpdateprdctonAcc on Subscription__c (before insert)
{
                //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
                Id recordTypeId = Schema.SObjectType.Subscription__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();
    List<Subscription__c> subscList = new List<Subscription__c>();
 
    for (Subscription__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }
    String str;
   
    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 (Subscription__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
     
        if(s.Membership_Type__c!= null)
        {
            cObjectID.add(s.Membership_Type__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__c,(SELECT ID,Membership_Type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
       
        for(Subscription__c s : subscList)
        {  
            if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Membership_Type__c).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product__c=pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
}
 
 Regards,
Sam
hi all,
i have written trigger but it gives only 44% code coverage so what can do forn increase it....?

My trigger is

trigger UpdateprdctonAcc on Subscription__c (after insert) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subscription__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();
    List<Subscription__c> subscList = new List<Subscription__c>();

    for (Subscription__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }
    String str;
    
    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 (Subscription__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Membership_Type__c!= null)
        {
            cObjectID.add(s.Membership_Type__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__c,(SELECT ID,Membership_Type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subscription__c s : subscList)
        {   
            if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Membership_Type__c).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product__c=pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
}


and test class for this is....

@istest
public class TestPrdctonacc 
{
    static testMethod void verifyProductUpdation()
    {
     // Set up the Account record.
    Account a = new Account(Name='Test Account' ,SLA__c='Gold', SLAExpirationDate__c=Date.today(),SLASerialNumber__c='jhbfs');
    insert a;
    
    Product2 p=new Product2(Name='Product Name');
    insert p;
    
    test.startTest();
    // Verify that the initial state is as expected.
    a = [SELECT Name,Product__c FROM Account WHERE Id = :a.Id];
    System.assertEquals(null,a.Product__c);

    // Set up the Opportunity record.
    String company=a.Id;
    Subscription__c sub = new Subscription__c(Name='ABC',Company_Name__c=company,Membership_Type__c=p.Id);
    // Cause the Trigger to execute.
    insert sub;
  
     // Verify that the results are as expected.
    a = [SELECT Name, Product__c FROM Account WHERE Id = :a.Id];
    System.assertEquals(null, a.Product__c);
        test.stopTest();
    }   
}

please tell me answer in brief

Thanks,
Sam
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 All,
     I am new to SFDC and i have written one trigger but i'm not able to write test class for it someone please tell me how can i write test class  for this trigger my Trigger is

trigger FetchVatvalue on Quote__c (before insert,before update) 
{
    //create reference table for lookup value
    Map<String, Decimal> vatMap = new Map<String, Decimal>();
    //build reference table for VAT rates
    for (VAT__c vat : [SELECT Name,Vat_Rate__c FROM VAT__c])
        vatMap.put(vat.Name, vat.Vat_Rate__c);
    //update Quote__c with VAT rate
    for (Quote__c q : trigger.new)
    {
        Decimal vatRate = vatMap.get(q.Country_Code__c);
        q.VAT_Rate__c = vatRate;
    }
}

this trigger is wrtten for automaticaly fetch value from another object using picklist

thank you,
Sam
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
Hello,
I have a number field on my account object that if greater than 1, I want it to change the account type to "Account Active"
Account Active is currently an option under the picklist field = Type.

What I am currently doing manually is running a report that shows customers with number of subscriptions. If I see one that has 1 or more subscription I have to go and change the account type to "Active Customer" currently it just stays as "Active Prospect" which is the default field.
Is this possible to automate with a trigger?
thank you-
  • November 06, 2014
  • Like
  • 1
Hi All,
   I have a requirement that when i calculate Net Amount=total=vat that after calculation this i have to fetch that formula field in my parent object so how can i fetch that field using Roll up Summary.
Thanks,
Sam
Hi All,
      I have one object which contains two field,i.e. Contry_Code__c & VAT_Rate__c which contains data like
Country Code           VAT Rate
USD                             0.20
IND                              0.19
EURO                           0.15

and i make this two fields on standard object.so how can fetch the VAT Rate  while i select Contry code(It may be Runtime or While Saving Data)
So please help me to solve this assignment.
Regards,
Sam.
Hi,
     I am trying to copy all cities from Student custom object in Address1 custom object into City__c field.all code working properly and code coverage also 100%
but the problem is that after running program cities not copied in Address table and i also trying to check program execution using System.Debug(''); but the statement not printed after executon in log my Code is here


global class CopyStudtoAdr_Batch implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
     String query='SELECT ID,City__c FROM Student__c';
     return Database.getQueryLocator(query);
   }
    global void execute(Database.BatchableContext BC, List<Student__c> scope)
    {
      System.debug('Batch Class Started....');
      //List<Address1__c> adrToUpdate = [Select id,StudentID__c,City__c from Address1__c where StudentID__c in : scope] ;
      //Set<String> setSturdentIds = new Set<String>();
      List<Address1__c> adrToUpdate = [Select Id,StudentID__c,City__c from Address1__c where StudentID__c in : Scope];

     Map<ID,Student__c> stdMap = new Map<ID,Student__c>(scope) ;
      
       // Loop to copy account Student to Address phone
       for(Address1__c adr : adrToUpdate)
        {
         adr.City__c =  stdMap.get(adr.StudentID__c).City__c ;
         }
       if(adrToUpdate.size() > 0)
       update adrToUpdate;
      }
     global void finish(Database.BatchableContext ctx)
      {}
}

Please check it and tell me Solution

Thanks,
Sam
How to Copy Custom Object Field record (i.e.phone) to Standard Object field.
Reply me.
hi,
     i have to copy one field all records(Which is already Stored)from custom object to Standard object by creating field on standard Object.
Anyone please tell me example of scheduling this type of job.
thanks,
Sam

Today we’re excited to announce the new Salesforce Developers Discussion Forums. We’ve listened to your feedback on how we can improve the forums.  With Chatter Answers, built on the Salesforce1 Platform, we were able to implement an entirely new experience, integrated with the rest of the Salesforce Developers site.  By the way, it’s also mobile-friendly.

We’ve migrated all the existing data, including user accounts. You can use the same Salesforce account you’ve always used to login right away.  You’ll also have a great new user profile page that will highlight your community activity.  Kudos have been replaced by “liking” a post instead and you’ll now be able to filter solved vs unsolved posts.

This is, of course, only the beginning  and because it’s built on the Salesforce1 Platform, we’re going to be able to bring you more features faster than ever before.  Be sure to share any feedback, ideas, or questions you have on this forum post.

Hats off to our development team who has been working tirelessly over the past few months to bring this new experience to our community. And thanks to each of you for helping to build one of the most vibrant and collaborative developer communities ever.