• sowmya thotthadi
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 1
    Likes Given
  • 6
    Questions
  • 14
    Replies
public class SendMailController {

    public String z { get; set; }
     public String y { get; set; }
    public String x { get; set; }
    public String attachname{get ; set;}
    public blob attachbody{get; set;}
    public void saveMethod() {
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};   
        mail.setToAddresses(xyz.split(';'));
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        
        Messaging.EmailFileAttachment fattch = new Messaging.EmailFileAttachment();
        fattch.setFileName(attachname);
        fattch.setBody(attachbody);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {fattch});
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
   }
  }
public class SendMailController {

    public String z { get; set; }

    public String y { get; set; }

    public String x { get; set; }

    public void saveMethod() {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};  
        mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
   
  }
<apex:form >
        <apex:pageBlock mode="edit" >
          <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Save" action="{!SaveMethod}"/>
            <apex:commandButton value="Cancel" action="{!CancelMethod}"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
              <apex:outputLabel value="Subject"/>
             <!-- <apex:outputField value="{!contactRecord.Subject__c}"/> --> 
            </apex:pageBlockSectionItem> <br/>
             <apex:pageBlockSectionItem >
              <apex:outputLabel value="Description"/>
             <!-- <apex:outputField value="{!contactRecord.Description}"/>  -->
            </apex:pageBlockSectionItem> <br/>
            <apex:pageBlockSectionItem >
              <apex:outputLabel value="Contact Name"/>
              <apex:inputField value="{!contactRecord.Contact_ReportIssue__c}"/> 
            </apex:pageBlockSectionItem><br/>
             <apex:pageBlockSectionItem >
              <apex:outputLabel value="Email"/>
             <!-- <apex:outputField value="{!contactRecord.Email}"/> --> 
            </apex:pageBlockSectionItem>   
          </apex:pageBlockSection>
        </apex:pageBlock>
      </apex:form>
</apex:page>


// controller
public class reportIssueRaised {
    public set<Contact> contactRecord {get; set;}
    
    public reportIssueRaised()
    {
      contactRecord = new set<Contact>([select id,Subject__c,Contact_ReportIssue__c,Description,Email from Contact]);
    }
    public PageReference CancelMethod() {
        return null;
    }


    public PageReference SaveMethod() {
        return null;
    }

  
}
public class AccountContactOppurtunitycon {
       
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
    for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
     for(id idrecord :accountid){
        InnerClass ic=new InnerClass();
        ic.opporidtunityList = id;
      }
   }
 }
 public class InnerClass{
      Public opportunity opportunityList{get; set;}
      Public list<OpportunityContactRole> contactRole{get;set;} 
    }
     
public class AccountContactOppurtunitycon {
       
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
    for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
     for(InnerClass ic :accountid){
      }
   }
 }
   public class InnerClass{
      Public opportunity opportunityList{get; set;}
      Public list<OpportunityContactRole> contactRole{get;set;} 
    }
      
     public List<InnerClass> innerList{get; set;}
      Public list<OpportunityContactRole> contactRole{get;set;}
        set<Id> accountid{get; set;}
   
}
My output should be 

table 1
  Account Name : 1st record
   opportunityid    contact  AccountName  amount
 
table 2
  Account Name : 2nd record
   opportunityid    contact  AccountName  ammount
 
I WAN TO ADD THE LIST OF RECORDS IN SET SOO THAT NO DUPLICATE
public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name  from OpportunityContactRole];
     accountid.addall(contactRole);
   }
}
public class SendMailController {

    public String z { get; set; }

    public String y { get; set; }

    public String x { get; set; }

    public void saveMethod() {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};  
        mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
   
  }
global class ReportIssueContactAssociationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
         return Database.getQueryLocator([SELECT Id, Contact__c, Email__c FROM Issue__c WHERE Contact__c = NULL]);  
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope){
        // loop through all Issue records and collect email addresses
        // Query Contacts based on Email Addresses
        // Create a Map of Email -- Contact
        
        Set<String> allEmails = new Set<String>();
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            allEmails.add(issue.Email__c);
        }
        
        Map<String, String> contactEmailContactIdMap = new Map<String, String>();
        for(Contact c : [SELECT id, Email FROM Contact WHERE EMail IN :allEmails]){
            contactEmailContactIdMap.put(c.Email, c.Id);
        }
        
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            issue.Contact__c = contactEmailContactIdMap.get(issue.Email__c);
        }
        Database.update(scope);
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
    

}

 
public class SendMailController {

    public String z { get; set; }
     public String y { get; set; }
    public String x { get; set; }
    public String attachname{get ; set;}
    public blob attachbody{get; set;}
    public void saveMethod() {
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};   
        mail.setToAddresses(xyz.split(';'));
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        
        Messaging.EmailFileAttachment fattch = new Messaging.EmailFileAttachment();
        fattch.setFileName(attachname);
        fattch.setBody(attachbody);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {fattch});
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
   }
  }
public class SendMailController {

    public String z { get; set; }

    public String y { get; set; }

    public String x { get; set; }

    public void saveMethod() {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};  
        mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
   
  }
public class AccountContactOppurtunitycon {
       
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
    for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
     for(id idrecord :accountid){
        InnerClass ic=new InnerClass();
        ic.opporidtunityList = id;
      }
   }
 }
 public class InnerClass{
      Public opportunity opportunityList{get; set;}
      Public list<OpportunityContactRole> contactRole{get;set;} 
    }
     
I WAN TO ADD THE LIST OF RECORDS IN SET SOO THAT NO DUPLICATE
public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name  from OpportunityContactRole];
     accountid.addall(contactRole);
   }
}
global class ReportIssueContactAssociationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
         return Database.getQueryLocator([SELECT Id, Contact__c, Email__c FROM Issue__c WHERE Contact__c = NULL]);  
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope){
        // loop through all Issue records and collect email addresses
        // Query Contacts based on Email Addresses
        // Create a Map of Email -- Contact
        
        Set<String> allEmails = new Set<String>();
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            allEmails.add(issue.Email__c);
        }
        
        Map<String, String> contactEmailContactIdMap = new Map<String, String>();
        for(Contact c : [SELECT id, Email FROM Contact WHERE EMail IN :allEmails]){
            contactEmailContactIdMap.put(c.Email, c.Id);
        }
        
        for(sObject so : scope){
            Issue__c issue = (Issue__c)so;
            issue.Contact__c = contactEmailContactIdMap.get(issue.Email__c);
        }
        Database.update(scope);
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
    

}