• Savi3
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 6
    Replies

Hi ,

 

   In my visualforce page i have a table of records with checkbox to each of them. I want to send email to contacts of the selected records . I'm using a custom button for this.

Vf code for the button :- 

apex:commandButton value="Send Email" action="{!SEmail}"/>

But i'm having issue with this.

 

Public PageReference SEmail(){
    
    List<ID> MailCont = new List<Id>();
    String Temp ='tempName';
    Messaging.MassEmailMessage Email = new Messaging.MassEmailMessage();
    Email.setTemplateId([Select id from EmailTemplate where Name =:Temp].Id);
    System.debug('No of tdaw******************************************************' + tdaw.size());
    for(Integer j=0;j<tdaw.size();j++){
    System.debug('Value in toDelete***********************************' + tdaw[j].toDelete);
    if(tdaw[j].isSelected == True )
    {
     MailCont.add(tdaw[j].tar.contact__c);
     
    }
    }
     
    System.debug('Value in ids***********************************' + MailCont);
    Email.setTargetObjectIds(MailCont);
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { Email });
    return null;
    }

 

While running i'm getting : SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target object ids (contact, lead or user): []

 

 

Anybody has idea??

Thank you.

Savi3.


I have to update the record if it is already in the system. I have an Object named 'Account' and its field 'Account ID'. The condition for updating the record is that for 'Account' the key is 'Account ID'. My question is:

1 : How can i assign the 'Account ID' key to the object 'Account'. I have an idea that i have to use map function here but how to use it i do not know. My understadning was that it should be something like

Map<Account_ID__c,Account__c> map1 = new Map<Account_ID__c,Account__c>(); //ITS AN ERROR !

So whats the right way to do it.

2 : How does mapping helps me in updating record. I mean i am sure it can be done without mapping the values so how (show with code) does it makes easy to update while using the map.

 

Thanks !

Hi,

I have couple of objects, In which i have defined a few custom field and one field as a standard field.

First, i will try to explain the reason why i have defined one field as a standard field.

The couple of object which i have defined represents the record and in my app if the record is already in the system i have to update its values. For every object i have been given a key like for eg for 'Contact' object i have been given 'Contact Email ' as a key. So, i have made the contact email as the standard field while the contact name as the custome field.

 

So, my question is,

1 : that does it even matters that if the key is custom or standard field ?

2 : Why there is no API name for standard field. how can one access standard field from apex code without it having the API name?

Also last but not the least

3 : what is the significance of having a key, i mean if a field is key then in what way is it seperate from other field .

 

Thanks

 

Hi,

 

    I'm getting "Compile Error: unexpected token: ')' at line 19 column 22"  while using System.debug.

I need to get the email of the logged in user. For that i wrote this code:

ID usrid = UserInfo.getUserId();

List<User> cusr = [Select Email From User where id =: usrid ];

String uEmail = cusr[0].Email;
System.debug(uEmail); ---------------------- (Line 19)

 

Can somebody tell me why this is happening and its solution? Please..

 

Thank you,

Savi3.


Hi ,

 

     I have a trigger which generates the standard field, Name of a custom object with  'a string + name of the corresponding Contact' before inserion/Updation.

My trigger:--

____________________________________________________________________________________________

trigger trgname on cusobj__c (before insert,before update) {
Set<ID> conid = new Set<ID>();
List<contact> lstContact = new List<contact>();
Map<ID,contact> Mapname = new Map<ID,contact>();
for( cusobj__c tar :Trigger.New)
{
conid.add(tar.Contact__c); // Storing all the contact ids for which the name needs to be used
}
system.debug('Inside the trigger to update the name');
//Getting all the contact records in a list to be used in the name field
lstContact = [select id,name,firstname,lastname from contact where id in : conid];

for(integer i =0; i <lstcontact.size(); i++)
{
Mapname.put(lstcontact[i].id,lstcontact[i]); // Putting the contact id and name in a map
}

for( cusobj__c tar :Trigger.New)
{
// tar.name = 'TD Rem - ' + mapname.get(tar.Contact__c).firstname +' ' + mapname.get(tar.Contact__c).lastname;
tar.name = 'TD Rem - ' + mapname.get(tar.Contact__c).name;
}

}

_____________________________________________________________________________________________

 

I do have a test class for this trigger . But getting  error 'Assertion Failed: Expected: 20, Actual: 0' 

 

My Testclass:-

____________________________________________________________________________________________

@isTest
Private class testTrgTrgname{
Static testMethod void methodname(){
Contact con = new Contact();
con.FirstName= 'fname';
con.LastName = 'lname';

insert con;
System.debug('value for contact name:' + con);
Contact con1 = new Contact();
con1.LastName = 'lname1';
insert con1;
//Insert test data

cusobj__c Tmapt = new cusobj__c();
Tmapt.Appointment_Created__c = True;
Tmapt.Target_date__c = System.today()+3;
Tmapt.Contact__c = con.id;

insert Tmapt;
System.debug('value for Tmapt name:' + Tmapt.Name);
System.debug('value for Tmapt :' + Tmapt);
List<cusobj__c> ltmd = new List<cusobj__c>();
ltmd =[Select Contact__c from cusobj__c where id =:Tmapt.id];
System.assertEquals(1,ltmd.Size());

System.assertEquals('TD Rem-fname lname', Tmapt.Name);
cusobj__c Tpt = new cusobj__c();
Tpt.Appointment_Created__c = True;
Tpt.Target_date__c = System.today()+ 5;
Tpt.Contact__c =con1.id;
insert Tpt;
System.assertEquals(Tpt.Name, con1.name);
Contact newcon = new Contact();
newcon.lastname = 'lnewcon';
insert newcon;
//cusobj__c Ltar =[Select Contact__c from cusobj__c where id := Tmapt.id];
//Tmapt.Cotnact__c = newcon.id;
//update Tmapt;

}
}

______________________________________________________________________________________________

  

 

Any idea?? Please help...

 

 

Thank You,

sav3