• Chitral Chadda
  • NEWBIE
  • 360 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 97
    Questions
  • 197
    Replies
triger on account which matches email and phone of the associated account, if both match then only insert contact record else throww error
trigger MatchPhoneonAccount on Contact (before insert)
{
    set<id> accIdset = new set<id>();
    for(Contact c :trigger.new)
    {
        if( c.accountid!=null)
            {
             accIdset.add(c.AccountId);
            }
    }
     map<id,account> accMap = new map<id,account>([Select id,Email__c , Phone from account where id in : accIdset]);
     
     
    for(contact c : trigger.new)
    {
         if(c.Email != null && c.Phone != null && accMap != null)
         {
          system.debug('*******Email'+c.Email);
          system.debug('*******Phone'+c.Phone);
            if(c.Email != accMap.get(c.accountid).Email__c &&  c.Phone != accMap.get(c.accountid).Phone)
            {
            system.debug('*******Dosent Matched'+c.Phone);
             c.adderror('Your phone and Email does not exists in out database .');
            }
         }
    
    }
}

no debug logs are generate and even though account and contact email, phone are different , the trigger dosent fire .
What is the difference  between static , public and private members of a class,? when we invoke class from trigger? Can anyone pls explain this with the help of an example.
when we invoke class with (static , public, private member) from trigger
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
IN THIS link
public class OpportunityTriggerHandler extends TriggerHandler {

  public OpportunityTriggerHandler() {}

  /* context overrides */

  protected void override beforeUpdate() {
    setLostOppsToZero();
  }

  protected void override afterInsert() {
    doSomeAfterInsertStuff();
  }

  protected void override beforeDelete() {
    doSomeStuffBeforeDelete();
  }

  /* private methods */

  ....

}


Here they have not defined triggerhandler class anywhere in the link provided
also, how is this done override , nothing specified :
 

/* context overrides */

  protected void override beforeUpdate() {
    setLostOppsToZero();
  }

  protected void override afterInsert() {
    doSomeAfterInsertStuff();
  }
 

 

I have a trigger which would limit no. of case created by a single user in a particular month, if case creation exceeds more than 99 (for particular owner id) than it would throw error ..

i wrote a test class for this but got only 12% coverage.
here is the trigger
 

trigger caseInsertion on Case (before insert) 
{
 case_insertions__c settings =case_insertions__c.getInstance('maximum');
 Decimal maxvalue = settings.maximumCount__c;
   map<id,integer> mapcount = new map<id,Integer>();
 set<id> owid = new set<id>();
 for(case t: trigger.new)
 {
 if(t.accountid!=null)
  {
  owid.add(t.ownerid);
  }
  mapcount.put(t.ownerid,0); 
 }
 

map<id,user> usermap = new map<id,user>([select id, Name from user where id in : owid]);

for(aggregateResult ar: [ select ownerid, count(id) from case where ownerid in :owid and CreatedDate=THIS_MONTH  group by ownerid])
{
mapcount.put((id)ar.get('ownerid'),(Integer)ar.get('expr0'));
}

for(case t:trigger.new)
{
 mapcount.put(t.ownerid,mapcount.get(t.ownerid)+1);
 if(mapcount.get(t.ownerid)> maxvalue)
  {
  t.addError('Cant create more cases');
  }
 } 
}
 
@isTest
public class TestcaseInsertion{
public static testMethod void TestcaseLimitInsertion()
{
case_settings__c settings= new case_settings__c();
settings.Name='max';
settings.Max_Number__c=99;
insert settings;

Profile p = [select id from profile where Name='System Administrator'];
user u1 = new user(alias='abc',email='abc@mail.com',emailencodingkey='UTF-8', lastname='Testing1', languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles', username='adminTas@testorg.com', profileid = p.id);
insert u1;


Account acc = new Account();
acc.Name='Chadda';
acc.ownerid=u1.id;
insert acc;

list<case> addcase = new list<case>();
//Date Tdate = System.Today();
for(Integer i = 0; i < 110; i++)
{

Case a = new Case (Origin='Phone',Status='New',Subject='hello' + i  + 'number',ownerid=u1.id,Accountid = acc.id);

addcase.add(a);

}


try{

insert addcase;
}
catch(Exception e)
{
System.debug('An error happened, as predicted!');
}

}
}

when i check to see which lines are not covered in trigger
line 5 to end is not covered , but i have performed this in test class .
 What is the difference  between static , public and private members of a class,? when we invoke class from trigger? Can anyone pls explain this with the help of an example.
when we invoke class with (static , public, private member) from trigger
trigger populateRivals on account(before insert,before update)
{    
  list<Rival__c> rvl = [select id,Name__c from rival__c ];
  map<string,id> rvlMap = new map<string,id>();
  for(Rival__c r:rvl)
  if(rvl!=null && rvl.size()>0)
  {
      {
          rvlMap.put(r.Name__c,r.id);
      }
  }      
 for(account acc: trigger.new)
 {  if(rvlMap!=null&&rvlMap.containsKey(acc.Rival_Picklist__c))
   {
     acc.Rival__c = rvlMap.get(acc.Rival_Picklist__c);
   }
  }  
}
here is the test class
@isTest
 public class TestpopulateRivals{
 public static testmethod void testpopulaterivals()
 {
     
     
     Rival__c rc = new Rival__c(Name ='Chitral');
     insert rc;
     
     account ac = new account(Name = 'Chitral Chadda');
     ac.Rival_Picklist__c = 'Chitral';
     
     insert ac;
     
    List<Account> acct =[Select id, Rival__c,Rival_Picklist__c FROM Account WHERE Rival__c =: rc.id];
     system.assertEquals(rc.id,acct[0].Rival__c);
    
  }
 }

i get error: System.ListException: List index out of bounds: 0
any idea?
here is the trigger
trigger populateRivals on account(before insert,before update)
{    
  list<Rival__c> rvl = [select id,Name__c from rival__c ];
  map<string,id> rvlMap = new map<string,id>();
  for(Rival__c r:rvl)
  if(rvl!=null && rvl.size()>0)
  {
      {
          rvlMap.put(r.Name__c,r.id);
      }
  }      
 for(account acc: trigger.new)
 {  if(rvlMap!=null&&rvlMap.containsKey(acc.Rival_Picklist__c))
   {
     acc.Rival__c = rvlMap.get(acc.Rival_Picklist__c);
   }
  }  
}
test class
@isTest
 public class TestpopulateRivals{
 public static testmethod void testpopulaterivals()
 {
     
     
     Rival__c rc = new Rival__c(Name ='Chitral');
     insert rc;
     
     account ac = new account(Name = 'Chitral Chadda');
     ac.Rival_Picklist__c = 'Chitral';
     
     insert ac;
     
     ac =[Select id, Rival__c,Rival_Picklist__c FROM Account WHERE Rival__c =: rc.id];
     system.assertEquals(rc.id,ac.Rival__c);
    
  }
 }
error:
System.QueryException: List has no rows for assignment to SObject



 
scenario :
suppost i hav accnt a1 and related contact as c1, c2
there addres_for_contact__c field on contact 
and final_address_of_contact__c field on account
if for c1 ...addres_for_contact__c='a';
for c2 ..addres_for_contact__c='b';
then on account  ..final address of contact = a,b
 
trigger listOfContactsOnAccount on contact (after insert , after update,after delete){ 
  set<id> accountIdSet = new set<id>();
  
  if( trigger.isInsert|| trigger.isUpdate){
    for(contact c : trigger.new){
      accountIdSet.add(c.AccountId);
    }
  }

  if(trigger.isDelete){
    for(contact c: trigger.old){
      accountIdSet.add(c.AccountId);
    }
  }
            
  //2.create map
  List<contact> cont = [ Select AccountId, Address_for_contact__c from contact where AccountId IN : accountIdSet ]; 
    
    //using a map of lists instead of a map of contacts
    Map<id,List<contact>> accountContactsMap = new map<id, List<contact>>();
    for(contact c : cont){
      //check if a entry in the map exists for the account
      if(!accountContactsMap.containsKey(c.accountId)){
        //if it doesnt then create one
        accountContactsMap.put(c.accountId, new List<Contact>());
      }
      //get the contact list for the account and add the contact in
      accountContactsMap.get(c.accountId).add(c);
    }
  
    List<Account> accountsToUpdate= new List<Account>();
    string l='';
    
              for(contact cn :trigger.new)
   {
     if(accountContactsMap != null)
         { 
              list<contact> aci = accountContactsMap.get(cn.AccountId);  
              account ac = new account(id=cn.AccountId);
                  {
                    for(contact c : aci)
                         
                         { if(l==null)
                          
                              {
                              l =   c.Address_for_Contact__c ;        
                              }
                             else
                             {
                             l= l+','+c.Address_for_contact__c;
                             }
                         }     
                             
               
                          ac.Final_address_of_contacts__c = l;
                          accountsToUpdate.add(ac);
                    }  
              
          }
          
   }
 update accountsToUpdate;  
}

test class:
@isTest
public class testlistOfContactsOnAccount
{
public static testMethod void accountaddress()
{


account acc = new account();
acc.Name='account name';
//acc.Final_address_of_contacts__c ='agsah,bawdgh';
insert acc;


List<Contact> clist = new List<Contact>();

contact ct1 = new contact(AccountId=acc.Id);
ct1.LastName='abc';
ct1.Address_for_contact__c='agsah';
clist.add(ct1);

contact ct2 = new contact(AccountId=acc.Id);
ct2.LastName='xyz';
ct2.Address_for_contact__c='bawdgh';
clist.add(ct2);
//ct2.accountid=acc.id

insert clist;

string l = null;
for(contact c : cList)
{
 if(l == null)
 { l= c.Address_for_contact__c;
 
 }
 else
 {
 l=l+','+c.Address_for_contact__c;
 }
}


acc.Final_address_of_contacts__c=l;
update acc;
account updt =[ select id,Final_address_of_contacts__c from account where id=:acc.id];
system.assertEquals(l, updt.Final_address_of_contacts__c);

  }
  }

when i do run test it shows pass
 but there is 0 % code coverage 
is the test class okay ?
I have a trigger which displays list of contact address on account 
suppost i hav accnt a1 and related contact as c1, c2
there addres_for_contact__c field on contact 
and final_address_of_contact__c field on account
if for c1 ...addres_for_contact__c='a';
for c2 ..addres_for_contact__c='b';
then on account  ..final address of contact = a,b
trigger listOfContactsOnAccount on contact (after insert , after update,after delete){ 
  set<id> accountIdSet = new set<id>();
  
  if( trigger.isInsert|| trigger.isUpdate){
    for(contact c : trigger.new){
      accountIdSet.add(c.AccountId);
    }
  }

  if(trigger.isDelete){
    for(contact c: trigger.old){
      accountIdSet.add(c.AccountId);
    }
  }
            
  //2.create map
  List<contact> cont = [ Select AccountId, Address_for_contact__c from contact where AccountId IN : accountIdSet ]; 
    
    //using a map of lists instead of a map of contacts
    Map<id,List<contact>> accountContactsMap = new map<id, List<contact>>();
    for(contact c : cont){
      //check if a entry in the map exists for the account
      if(!accountContactsMap.containsKey(c.accountId)){
        //if it doesnt then create one
        accountContactsMap.put(c.accountId, new List<Contact>());
      }
      //get the contact list for the account and add the contact in
      accountContactsMap.get(c.accountId).add(c);
    }
  
    List<Account> accountsToUpdate= new List<Account>();
    string l='';
    
              for(contact cn :trigger.new)
   {
     if(accountContactsMap != null)
         { 
              list<contact> aci = accountContactsMap.get(cn.AccountId);  
              account ac = new account(id=cn.AccountId);
                  {
                    for(contact c : aci)
                         
                         { if(l==null)
                          
                              {
                              l =   c.Address_for_Contact__c ;        
                              }
                             else
                             {
                             l= l+','+c.Address_for_contact__c;
                             }
                         }     
                             
               
                          ac.Final_address_of_contacts__c = l;
                          accountsToUpdate.add(ac);
                    }  
              
          }
          
   }
 update accountsToUpdate;  
}
 
@isTest
public class testlistOfContactsOnAccount
{
public static testMethod void accountaddress()
{


account acc = new account();
acc.Name='account name';
//acc.Final_address_of_contacts__c ='agsah,bawdgh';
insert acc;


List<Contact> clist = new List<Contact>();

contact ct1 = new contact(AccountId=acc.Id);
ct1.LastName='abc';
ct1.Address_for_contact__c='agsah';
clist.add(ct1);

contact ct2 = new contact(AccountId=acc.Id);
ct2.LastName='xyz';
ct2.Address_for_contact__c='bawdgh';
clist.add(ct2);
//ct2.accountid=acc.id

insert clist;

string l = null;
for(contact c : cList)
{
 if(l == null)
 { l= c.Address_for_contact__c;
 
 }
 else
 {
 l=l+','+c.Address_for_contact__c;
 }
}


acc.Final_address_of_contacts__c=l;
update acc;
account updt =[ select id,Final_address_of_contacts__c from account where id=:acc.id];
system.assertEquals(l, updt.Final_address_of_contacts__c);

  }
  }

when i do run test it shows pass : but there is 0 % code coverage 
i m unsure what cud b d reason 
trigger setAccountToProspect on Opportunity (after insert , after update) {

set<id> accId = new set<id>();
for(opportunity op :trigger.new)
 {
   if(op.AccountId!=null)
    {
     accId.add(op.AccountId);
    }
 }
 list<account> accMap = [ select Type from account where id IN : accId ];
 map<id,account> accMaps = new map<id,account>();
 for(account a :accMap)
 {
 accMaps.put(a.id,a);
 }
//     map<id,account> accMaps = new map<id,account>([select id, Type from account where id IN : accId ]);
list<account> ac = new list<account>();

for(opportunity o :trigger.new)
    {
      if(accMaps.get(o.accountid).Type=='Other')
           {
            if(o.StageName=='Prospecting' || o.StageName=='Qualification' || o.StageName=='Needs Analysis')
            {
             account a = accMaps.get(o.Accountid); 
              a.Type = 'Prospect';
              ac.add(a);
            }  
           } 
     }
     update ac;      
}
hello whenever from opportunity if stage name is prospecting,qualification etc
ur parent account type is set to prospect then.
 
@isTest
public class testsetAccountToProspect
{
static testMethod void updateaccount()
{

 account acct = new account();
 acct.name='ABC';
 acct.Type='Other';
 insert acct;
  
  opportunity oppt = new opportunity(Accountid=acct.id);
  oppt.StageName='Prospecting';
  oppt.Name='Test';
  oppt.closeDate = date.today() + 30;
  insert oppt;
  
  
  acct = [ select id,type from account where id=: acct.id];
  system.assertequals('Prospect',acct.Type);
 }
 }

help with test class 
I have a trigger which displays list of contact address on account 
suppost i hav accnt a1 and related contact as c1, c2
there addres_for_contact__c field on contact 
and final_address_of_contact__c field on account
if for c1 ...addres_for_contact__c='a';
for c2 ..addres_for_contact__c='b';
then on account  ..final address of contact = a,b
trigger listOfContactsOnAccount on contact (after insert , after update,after delete){ 
  set<id> accountIdSet = new set<id>();
  
  if( trigger.isInsert|| trigger.isUpdate){
    for(contact c : trigger.new){
      accountIdSet.add(c.AccountId);
    }
  }

  if(trigger.isDelete){
    for(contact c: trigger.old){
      accountIdSet.add(c.AccountId);
    }
  }
            
  //2.create map
  List<contact> cont = [ Select AccountId, Address_for_contact__c from contact where AccountId IN : accountIdSet ]; 
    
    //using a map of lists instead of a map of contacts
    Map<id,List<contact>> accountContactsMap = new map<id, List<contact>>();
    for(contact c : cont){
      //check if a entry in the map exists for the account
      if(!accountContactsMap.containsKey(c.accountId)){
        //if it doesnt then create one
        accountContactsMap.put(c.accountId, new List<Contact>());
      }
      //get the contact list for the account and add the contact in
      accountContactsMap.get(c.accountId).add(c);
    }
  
    List<Account> accountsToUpdate= new List<Account>();
    string l='';
    
              for(contact cn :trigger.new)
   {
     if(accountContactsMap != null)
         { 
              list<contact> aci = accountContactsMap.get(cn.AccountId);  
              account ac = new account(id=cn.AccountId);
                  {
                    for(contact c : aci)
                         
                         { if(l==null)
                          
                              {
                              l =   c.Address_for_Contact__c ;        
                              }
                             else
                             {
                             l= l+','+c.Address_for_contact__c;
                             }
                         }     
                             
               
                          ac.Final_address_of_contacts__c = l;
                          accountsToUpdate.add(ac);
                    }  
              
          }
          
   }
 update accountsToUpdate;  
}

here is the test class
@isTest
public class testlistOfContactsOnAccount
{
public static testMethod void accountaddress()
{


account acc = new account();
acc.Name='account name';
//acc.Final_address_of_contacts__c ='agsah,bawdgh';
insert acc;


List<Contact> clist = new List<Contact>();

contact ct1 = new contact(AccountId=acc.Id);
ct1.LastName='abc';
ct1.Address_for_contact__c='agsah';
clist.add(ct1);

contact ct2 = new contact(AccountId=acc.Id);
ct2.LastName='xyz';
ct2.Address_for_contact__c='bawdgh';
clist.add(ct2);
//ct2.accountid=acc.id

insert clist;

string l = null;
for(contact c : cList)
{
 if(l == null)
 { l= c.Address_for_contact__c;
 
 }
 else
 {
 l=l+','+c.Address_for_contact__c;
 }
}


acc.Final_address_of_contacts__c=l;
update acc;
account updt =[ select id,Final_address_of_contacts__c from account where id=:acc.id];
system.assertEquals(l, updt.Final_address_of_contacts__c);

  }
  }

when i do run test it shows pass : but there is 0 % code coverage 
i m unsure what cud b d reason 
i have a trigger which displays list of contact address on account 
suppost i hav accnt a1 and related contact as c1, c2
there addres_for_contact__c field on contact 
and final_address_of_contact__c field on account
if for c1 ...addres_for_contact__c='a';
for c2 ..addres_for_contact__c='b';
then on account  ..final address of contact = a,b
trigger listOfContactsOnAccount on contact (after insert , after update,after delete){ 
  set<id> accountIdSet = new set<id>();
  
  if( trigger.isInsert|| trigger.isUpdate){
    for(contact c : trigger.new){
      accountIdSet.add(c.AccountId);
    }
  }

  if(trigger.isDelete){
    for(contact c: trigger.old){
      accountIdSet.add(c.AccountId);
    }
  }
            
  //2.create map
  List<contact> cont = [ Select AccountId, Address_for_contact__c from contact where AccountId IN : accountIdSet ]; 
    
    //using a map of lists instead of a map of contacts
    Map<id,List<contact>> accountContactsMap = new map<id, List<contact>>();
    for(contact c : cont){
      //check if a entry in the map exists for the account
      if(!accountContactsMap.containsKey(c.accountId)){
        //if it doesnt then create one
        accountContactsMap.put(c.accountId, new List<Contact>());
      }
      //get the contact list for the account and add the contact in
      accountContactsMap.get(c.accountId).add(c);
    }
  
    List<Account> accountsToUpdate= new List<Account>();
    string l='';
    
              for(contact cn :trigger.new)
   {
     if(accountContactsMap != null)
         { 
              list<contact> aci = accountContactsMap.get(cn.AccountId);  
              account ac = new account(id=cn.AccountId);
                  {
                    for(contact c : aci)
                         
                         { if(l==null)
                          
                              {
                              l =   c.Address_for_Contact__c ;        
                              }
                             else
                             {
                             l= l+','+c.Address_for_contact__c;
                             }
                         }     
                             
               
                          ac.Final_address_of_contacts__c = l;
                          accountsToUpdate.add(ac);
                    }  
              
          }
          
   }
 update accountsToUpdate;  
}


i m facing issue how to match the strings or may be i m wrong
@isTest
public class testlistOfContactsOnAccount
{
public static testMethod void accountaddress()
{


account acc = new account();
acc.Name='account name';
//acc.Final_address_of_contacts__c ='rp bagh,karol bagh';
insert acc;


List<Contact> clist = new List<Contact>();

contact ct1 = new contact(AccountId=acc.Id);
ct1.LastName='abc';
ct1.Address_for_contact__c='rp bagh';
clist.add(ct1);

contact ct2 = new contact(AccountId=acc.Id);
ct2.LastName='xyz';
ct2.Address_for_contact__c='karol bagh';
clist.add(ct1);
//ct2.accountid=acc.id


insert clist;

account updt =[ select id,Final_address_of_contacts__c from account where id=:acc.id];
system.assertEquals('rp bagh,karol bagh', updt.Final_address_of_contacts__c);

List<Contact> deleteList = new List<Contact>();

    deleteList.add(ct1);
    delete deleteList;
    
account updt1 =[ select id,Final_address_of_contacts__c from account where id=:acc.id];
system.assertEquals('karol bagh', updt1.Final_address_of_contacts__c);

  }
  }


any help ?
trigger LeadUpdate on Lead (before Update) 
{ 
   
  
 //list<lead> addhere = new list<lead>();
 for( lead ld :trigger.new)
  {
   if(ld.Do_Not_Market__c=='Blacklisted' && trigger.oldmap.get(ld.id).Do_Not_Market__c!= 'Blacklisted')
   {
    //Lead renewal = new lead();
    ld.Do_Not_Mail__c=True;
    ld.DoNotCall=True;
    ld.Email_Opt_Out__c=True;
    ld.Status='Dead';
    ld.LastName=ld.Lastname +'Renewal';
    ld.Company='ABC';
    //addhere.add(renewal);
    }
    
   
   }
   //insert addhere;
 }

only when do not market = blacklisted then it performs action
do not mail =true;
email opt out = true;


but with this test class initiall i inserted do not market = DNC this season
and then when i change do not market = blacklisted 
and test code
 i get error ....System.AssertException: Assertion Failed: Expected: true, Actual: false at line 24
@isTest
public class testLeadUpdate
{
static testMethod void updatelead()
{

lead ld = new lead();
//ld.Do_Not_Market__c='DNC This Season';
//ld.Do_Not_Mail__c=false;
//ld.Email_Opt_Out__c=false;
 //ld.LastName='Renewal';
//ld.Company='ABC';


ld.Do_Not_Market__c='DNC This Season';
ld.LastName='Renewal';
ld.Company='ABC';
insert ld;
system.assertEquals(false,ld.Do_Not_Mail__c);//line 24
system.assertEquals(false,ld.Email_Opt_Out__c);

ld.Do_Not_Market__c='Blacklisted';
update ld;
system.assertEquals(true,ld.Do_Not_Mail__c);
system.assertEquals(true,ld.Email_Opt_Out__c);






}
}

if i do like
@isTest
public class testLeadUpdate
{
static testMethod void updatelead()
{

lead ld = new lead();


ld.Do_Not_Market__c='DNC This Season';
ld.LastName='Renewal';
ld.Company='ABC';
insert ld;
system.assertEquals(false,ld.Do_Not_Mail__c);
system.assertEquals(false,ld.Email_Opt_Out__c);

ld.Do_Not_Market__c='Blacklisted';
update ld;
system.assertEquals(false,ld.Do_Not_Mail__c);
system.assertEquals(false,ld.Email_Opt_Out__c);


}
}

i get 100 % coverage...

but these fields should be set to true when do not market = blacklisted .
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdatesOnLead caused an unexpected exception, contact your administrator: UpdatesOnLead: execution of BeforeUpdate caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.UpdatesOnLead: line 14, column 1
trigger UpdatesOnLead on Lead (before Update,before insert) 
{ list<lead> addhere = new list<lead>();
 for( lead ld :trigger.new)
  {
   if(ld.Do_Not_Market__c=='Blacklisted' && trigger.oldmap.get(ld.id).Do_Not_Market__c!= 'Blacklisted')
   {
    ld.Do_Not_Mail__c=True;
    ld.DoNotCall=True;
    ld.Email_Opt_Out__c=True;
    ld.Status='Dead';
    addhere.add(ld);
    }
   }
   insert addhere;
 }

i want to insert new lead whenevr blackisted is selected on update
bt i get this error

When i send the  image in the htmlbody using img tag , i have stored the image in document .
i have checked "externally available use" checkbox on document also .. 
I am able to see that image from my cell phone but , when  I login desktop  i cant see any image there in the mail 

it says click here to see image when i click there is no image , although i am able to see image in my cell phone
 

mail.setHtmlBody(' Hello Chadda !! <image src="https://chitral-dev-ed--c.ap1.content.force.com/servlet/servlet.ImageServer?id=01590000006MdbA&oid=00D90000000vuPf&lastMod=1418471178000" ');
 


I am using html email status related list to track #times opened mail  and other .

Is there any workaroud to check that email is opened or not, no. of times openen etc for emails sent through code.??
Bcz HTML email status reports builts reports for emails based on html email template  .

can we track all those html email which are sent through code ?

I have a picklist Priority__c on contact whith values 1 ,2,3...upto 10
i want that for single account , there shud be no duplicate picklist  value of priority in contacts (limit 10 )
if user tries to enter a duplicate value of priority , then display error.

I am stuck at this map concept.
since in MAP there shoould be single id of account  and list of contacts storing priority
i m quering it from account list but something is wrong.
trigger UniquePriority on Contact (before insert,before update) {
 set<id> accId = new set<id>();
     for(contact c: trigger.new)
     {
      if (c.accountid!=null)
       {
        accId.add(c.accountId);
      }
     }
   
 //Here i used  account list to maintain unique id (single account id)  with limit of 10 contacts   
    list<account> acc = [select id ,(select Priority__c from contacts where Priority__c!=null) from account where id In: accid ];
    map<id,list<contact>> accMap = new map<id,list<contact>>();

//[Error] Error: Compile Error: Loop variable must be of type SOBJECT:Account at line 14 column 17
//But if i change this to for(account a : acc.contacts)  i will have to chasnge map to map<id,list<account>> and everything goes wrong then.
    for(contact a : acc)
     {
      if(!accMap.containskey(a.accountid))
       {
       accMap.put(a.accountid,new List<contact>());
       }
      else
      {
      accMap.get(a.accountid).add(a);
      }
     }
     
  for(contact c: trigger.new)
  {   
        if(accMap.containsKey(c.accountid) && c.Priority__C!=null)
         {
               list<contact> dupPriority =accMap.get(c.Accountid);
               {
                    for( contact dp: dupPriority)
                    {
                      if( c.Priority__c == dp.Priority__c)
                     {
                     c.addError('Same priority exists');
                     }
                    } 
                }
          }
   }      
       
       
     
}
trigger CountFemales1 on Contact (after insert,after update,after delete)
{
set<id>  conId = new set<id>();

 if(trigger.isInsert||trigger.isUpdate)
 {
  for(contact c: trigger.new)
  {
   if(c.accountid!=null)
   {
   conId.add(c.accountid);
   }
  }
 }
 
 
 if(trigger.isDelete)
 {
 for(contact c:trigger.old)
 {
  if(c.accountid!=null)
  {
  conId.add(c.accountid);
  }
 }
 
 
list<account> FemaleList = [select id  ,(select Accountid, Sex__c from contacts where Sex__c='Female') from account where id In :conId];
 map<id,integer> countMap = new map<id,integer>();
 for(account a :FemaleList)
 {
 countMap.put(a.id, a.contacts.size());
 }
 
 
 list<account> countlist = [select Count_of_Females__c from account where id in :conId];
 for(account a : countlist)
 {
 //Integer countoffemale = countMap.get(a.id);
 //a.Count_of_Females__c= countoffemale;
  a.Count_of_Females__c= countMap.get(a.id);
 }
 update countList;

}  
    
}


I want that it should display the count of no. of contacts where sex = female 
it m able to  save the trigger but  there is no result  displayed ( its not displaying the count of females in account , even though i have contacts where sex= female in the picklist)

any help?
i reuire that if IE version is 8 or less then it should display a pop up or a message
but its not working

<!DOCTYPE html>
<html>
<body>
<script>
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null) {
            rv = parseFloat( RegExp.$1 );
        }
    }

    return rv;
}

function checkVersion() {
    var msg = "You're not using Internet Explorer.";
    var ver = getInternetExplorerVersion();

    if ( ver > -1 ) {
        if ( ver >= 9.0 ) {
            msg = "You're using a recent copy of Internet Explorer."
        }
        else {
            msg = "You should upgrade your copy of Internet Explorer.";
        }
    }
    alert(msg);
}
</script>
</body>
</html> 


no pop is displayed with this or message

In visualforce email template is is it necessary that for customer controller it must contains component.
suppose in this
Dear {!lead.Name}
Thank you for choosing {!relatedTo.Account.Name} to assist you with your property taxes.  As we discussed over the 

phone, {!relatedto.Contact.Mobile__c} will be contacting you if we need additional information regarding your 

application. Their contact information, if you have any concerns or questions, is as follows:

{!relatedTo.Account.email}



now in all these dynamic fields like  eg used above {!relatedTo.Account.email}

is it necessary  that they all must be related to the "relatedToType" in the template...what if the dynamic field fields do not belong to the relatedToType object.

also, 1 thing more since we have either person or businees account  is this condition right to use
if it is business account then i want it shoul pick phone_1__c elase if business account then pick 'phone' field.
 

now, under contact information 
in the first column  is value of picklist : phone type 1, type 2 , type 3 ( all 3 picklist have values --- home , cell work ,fax)
nd last coloumn is radio button

preferred contact type is text field in which we enter eithr home or wor or fax or cell . (the field is on standard page)
now i want that suppose user entered preferred type of contact as cell than 1st rows radio button should be selected.
like wise if preffered type of contact is work then 2nd rows radio button should be selected.
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" action="{!map1}" /> Preferred
<input type="radio" name="optionsRadios" id="optionsRadios2"  value="option2" action="{!map1}" /> Preferred
<input type="radio" name="optionsRadios" id="optionsRadios3" value="option3"  action="{!map1}" /> Preferred


dependin on what preffered contact type (text field ) is home/ work/ cell  (entered by user)

that particular radio button shud be selected.
i tried this but its not working..

public pageReference map1()
{


if(account.Phone_Type_1__c==account.Preferred_Contact_Type__c)
{

radio=true;
}
return null;
if(account.Phone_Type_2__c==account.Preferred_Contact_Type__c)
{
radio=true;

}
return null;
if(account.Phone_Type_3__c==account.Preferred_Contact_Type__c)
{
radio=true;

}
return null;

}
i get error:
 Unknown property 'AccountStandardController.map1'
User-added image
triger on account which matches email and phone of the associated account, if both match then only insert contact record else throww error
trigger MatchPhoneonAccount on Contact (before insert)
{
    set<id> accIdset = new set<id>();
    for(Contact c :trigger.new)
    {
        if( c.accountid!=null)
            {
             accIdset.add(c.AccountId);
            }
    }
     map<id,account> accMap = new map<id,account>([Select id,Email__c , Phone from account where id in : accIdset]);
     
     
    for(contact c : trigger.new)
    {
         if(c.Email != null && c.Phone != null && accMap != null)
         {
          system.debug('*******Email'+c.Email);
          system.debug('*******Phone'+c.Phone);
            if(c.Email != accMap.get(c.accountid).Email__c &&  c.Phone != accMap.get(c.accountid).Phone)
            {
            system.debug('*******Dosent Matched'+c.Phone);
             c.adderror('Your phone and Email does not exists in out database .');
            }
         }
    
    }
}

no debug logs are generate and even though account and contact email, phone are different , the trigger dosent fire .
What is the difference  between static , public and private members of a class,? when we invoke class from trigger? Can anyone pls explain this with the help of an example.
when we invoke class with (static , public, private member) from trigger
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
IN THIS link
public class OpportunityTriggerHandler extends TriggerHandler {

  public OpportunityTriggerHandler() {}

  /* context overrides */

  protected void override beforeUpdate() {
    setLostOppsToZero();
  }

  protected void override afterInsert() {
    doSomeAfterInsertStuff();
  }

  protected void override beforeDelete() {
    doSomeStuffBeforeDelete();
  }

  /* private methods */

  ....

}


Here they have not defined triggerhandler class anywhere in the link provided
also, how is this done override , nothing specified :
 

/* context overrides */

  protected void override beforeUpdate() {
    setLostOppsToZero();
  }

  protected void override afterInsert() {
    doSomeAfterInsertStuff();
  }
 

 

in below code example i want to compare the e-mail and contact number of customer and complaint object. complaint and customer are in lookup relationship. i want output like if before registering a compliant it should check the same e-mail address and phone number must be in customer record.

trigger Demo on Complaint__c (before insert) {
    
    if(trigger.isBefore)
    {
        if(trigger.isInsert)
        {
            for(Shan__Complaint__c a:Trigger.new)
            {
                for(Shan__bsnl_customer__c b:Trigger.new)
                   if(a.Shan__Phone_Number_del__c== b.Shan__cust_contact__c && a.Shan__E_mail_del__c==b.Shan__cust_email__c)
                    {
                            a.adderror('Customer is not in Database');
                    
                    }
            }
        
        }

I have a trigger which would limit no. of case created by a single user in a particular month, if case creation exceeds more than 99 (for particular owner id) than it would throw error ..

i wrote a test class for this but got only 12% coverage.
here is the trigger
 

trigger caseInsertion on Case (before insert) 
{
 case_insertions__c settings =case_insertions__c.getInstance('maximum');
 Decimal maxvalue = settings.maximumCount__c;
   map<id,integer> mapcount = new map<id,Integer>();
 set<id> owid = new set<id>();
 for(case t: trigger.new)
 {
 if(t.accountid!=null)
  {
  owid.add(t.ownerid);
  }
  mapcount.put(t.ownerid,0); 
 }
 

map<id,user> usermap = new map<id,user>([select id, Name from user where id in : owid]);

for(aggregateResult ar: [ select ownerid, count(id) from case where ownerid in :owid and CreatedDate=THIS_MONTH  group by ownerid])
{
mapcount.put((id)ar.get('ownerid'),(Integer)ar.get('expr0'));
}

for(case t:trigger.new)
{
 mapcount.put(t.ownerid,mapcount.get(t.ownerid)+1);
 if(mapcount.get(t.ownerid)> maxvalue)
  {
  t.addError('Cant create more cases');
  }
 } 
}
 
@isTest
public class TestcaseInsertion{
public static testMethod void TestcaseLimitInsertion()
{
case_settings__c settings= new case_settings__c();
settings.Name='max';
settings.Max_Number__c=99;
insert settings;

Profile p = [select id from profile where Name='System Administrator'];
user u1 = new user(alias='abc',email='abc@mail.com',emailencodingkey='UTF-8', lastname='Testing1', languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles', username='adminTas@testorg.com', profileid = p.id);
insert u1;


Account acc = new Account();
acc.Name='Chadda';
acc.ownerid=u1.id;
insert acc;

list<case> addcase = new list<case>();
//Date Tdate = System.Today();
for(Integer i = 0; i < 110; i++)
{

Case a = new Case (Origin='Phone',Status='New',Subject='hello' + i  + 'number',ownerid=u1.id,Accountid = acc.id);

addcase.add(a);

}


try{

insert addcase;
}
catch(Exception e)
{
System.debug('An error happened, as predicted!');
}

}
}

when i check to see which lines are not covered in trigger
line 5 to end is not covered , but i have performed this in test class .
Hi all, 
           I am beginer of salesforce.Please any one help me  the following code implementation. how to Write Apex class to update all the opportunities close date as today()?

Thanks in advance
trigger populateRivals on account(before insert,before update)
{    
  list<Rival__c> rvl = [select id,Name__c from rival__c ];
  map<string,id> rvlMap = new map<string,id>();
  for(Rival__c r:rvl)
  if(rvl!=null && rvl.size()>0)
  {
      {
          rvlMap.put(r.Name__c,r.id);
      }
  }      
 for(account acc: trigger.new)
 {  if(rvlMap!=null&&rvlMap.containsKey(acc.Rival_Picklist__c))
   {
     acc.Rival__c = rvlMap.get(acc.Rival_Picklist__c);
   }
  }  
}
here is the test class
@isTest
 public class TestpopulateRivals{
 public static testmethod void testpopulaterivals()
 {
     
     
     Rival__c rc = new Rival__c(Name ='Chitral');
     insert rc;
     
     account ac = new account(Name = 'Chitral Chadda');
     ac.Rival_Picklist__c = 'Chitral';
     
     insert ac;
     
    List<Account> acct =[Select id, Rival__c,Rival_Picklist__c FROM Account WHERE Rival__c =: rc.id];
     system.assertEquals(rc.id,acct[0].Rival__c);
    
  }
 }

i get error: System.ListException: List index out of bounds: 0
any idea?
here is the trigger
trigger populateRivals on account(before insert,before update)
{    
  list<Rival__c> rvl = [select id,Name__c from rival__c ];
  map<string,id> rvlMap = new map<string,id>();
  for(Rival__c r:rvl)
  if(rvl!=null && rvl.size()>0)
  {
      {
          rvlMap.put(r.Name__c,r.id);
      }
  }      
 for(account acc: trigger.new)
 {  if(rvlMap!=null&&rvlMap.containsKey(acc.Rival_Picklist__c))
   {
     acc.Rival__c = rvlMap.get(acc.Rival_Picklist__c);
   }
  }  
}
test class
@isTest
 public class TestpopulateRivals{
 public static testmethod void testpopulaterivals()
 {
     
     
     Rival__c rc = new Rival__c(Name ='Chitral');
     insert rc;
     
     account ac = new account(Name = 'Chitral Chadda');
     ac.Rival_Picklist__c = 'Chitral';
     
     insert ac;
     
     ac =[Select id, Rival__c,Rival_Picklist__c FROM Account WHERE Rival__c =: rc.id];
     system.assertEquals(rc.id,ac.Rival__c);
    
  }
 }
error:
System.QueryException: List has no rows for assignment to SObject