• iswarya sekar 7
  • NEWBIE
  • 80 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 49
    Replies
public class updateNameClass{
   // public String updateValue{get;set;}
    public updateNameClass(ApexPages.Standardcontroller controller){
    } 
    public PageReference gotostep2(){
        PageReference pref2=New PageReference('/apex/step2page');
        pref2.setRedirect(True);
        return pref2;
    }
    public List<Opportunity>optyList{set;get;}
    public  Map<String, String>labelToAPIName {set;get;}
    public String fldValue {set;get;}
    public List<Opportunity>optyUpdate{set;get;}
    public updateNameClass(ApexPages.StandardSetcontroller controller){
        this.optyList=(List<Opportunity>)Controller.getRecords() ;
        labelToAPIName = new Map <String, String> ();
        
        Map<String, Schema.SObjectField>fieldsMap = Schema.SObjectType.Opportunity.fields.getMap();
        for (Schema.SObjectField field :fieldsMap.values())
        {
          //  System.debug('label'+field.getDescribe().getLabel()+'*********Api**********'+field.getDescribe().getName());
            labelToAPIName.put(field.getDescribe().getLabel(), field.getDescribe().getName());
        }
    }
    
    public pageReference updateMethod(){
        optyUpdate=new List<opportunity>();
        
        String fld = System.currentPageReference().getParameters().get('fieldName');
        System.debug('fld'+fldValue+'==='+fld); 
        if(labelToAPIName.containsKey(fld)){
            String apiFld=labelToAPIName.get(fld);
            System.debug('api'+apiFld);
            for(opportunity op:optyList){
                Map<String, Object>fieldValueMap = new Map<String, Object>();
                fieldValueMap.put(apiFld,fldValue );
                op.put(apiFld,fldValue);
                optyUpdate.add(op);
            }                         
        } 
        Update(optyUpdate);
        System.debug('optyUpdate'+optyUpdate);
        PageReference pref2=New PageReference('/apex/oppupdatepage');
        pref2.setRedirect(True);
        return pref2;
    }     
}

when i give a new value for a field it should be updated in all records(Mass update records from list view). its updating for string fields but not for other fields like date, boolean, decimal etc. Can anyone help me on this? Thanks in Advance!
when i enter value for amount field, that value should be updated in all records of a list view.
can anyone please help me on this. 
im in urgent. its a client requirement.
HI,

I need to display opportunity fields as dropdown in VF page. can anyone suggest me the idea?
curl "https://xxx.salesforce.com/services/data/v35.0/query/?q=SELECT+Id,+Name,+Phone+FROM+Account" -H "Authorization: Bearer <access token> "



But this only fetching 2000 records. I need all 1Lakhs records to be fetched. is there anyway?
I need to fetch all records from all objects using REST API cURL. can anyone please help me?
public class PrintPageController {
    Public CPL_Protocols__c cp{get;set;}
    public ID cplid{get;set;} // used to pass values from controller to VF page.
    
    public PrintPageController(ApexPages.StandardController controller) {    // Default Constructor Method to fetch data.
        cplid = apexpages.currentpage().getparameters().get('Id');
        
        if(cplid!=null){
            cp =[select id,ownerId,Study_Protocol_Number__c,Approval_Step_Status__c,Status_Date_Time_Stamp__c,Protocol_Status__c, Labels_Due_Date__c,
                 Number_of_Labels_to_Printed__c,Contact__c,user_email__c,Name,
                 Number_of_Study_Sites__c,Study_Type__c,Treatment_Period__c,Country__c,
                 Study_Phase__c,Study_Protocol_Description__c,No_of_Treatment_Grp__c,Enrollment_Period__c,
                 Study_Duration__c,Dosing_Regimen__c,Primary_Packaging__c,Secondary_Packaging__c,Label_Information__c,
                 Labeling_Lot_Number__c,Storage_Requirements__c,Max_Exposure_Time__c,Label_Expiration_Date__c,
                 Packaging_Site__c,Labeling_Site__c,Quantity_Required__c,Sampling_Requirements__c,CreatedById,Labeling_Package_Instructions__c,
                 Calculated_Qty_to_be_Prepared__c,Randomization__c,Randomization_File_Acknowledgement__c,LastModifiedById
                 from CPL_Protocols__c where id=:cplid]; // using ID, it displays the CPL Fields.
            system.debug('The value of CPL Prtocol is'+cp); // To Find and Resolve problems in execution.
        } 
    }
}





VF page:

<apex:page standardController="CPL_Protocols__c" renderAs="pdf" applyBodyTag="false" docType="html-5.0" standardStylesheets="false" showHeader="false" extensions="PrintPageController">
    
    <apex:form >
        <apex:pageBlock title="CPL Request Information Detail">
            <apex:pageBlockSection title="Status" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.OwnerId}"/>  
                <apex:outputfield value="{!CPL_Protocols__c.Study_Protocol_Number__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Approval_Step_Status__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Status_Date_Time_Stamp__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Protocol_Status__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labels_Due_Date__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Number_of_Labels_to_Printed__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Contact__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.user_email__c}"/>  
            </apex:pageBlockSection> 
        </apex:pageBlock>
        
        
        <apex:pageblock >
            <apex:pageBlockSection title="Study Information" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Name}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Number_of_Study_Sites__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Type__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Treatment_Period__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Country__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Phase__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Protocol_Description__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.No_of_Treatment_Grp__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Enrollment_Period__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Duration__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Dosing_Regimen__c}"/>  
            </apex:pageBlockSection>
        </apex:pageblock>
        
        <apex:pageblock >
            <apex:pageBlockSection title="Product Information" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Primary_Packaging__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Secondary_Packaging__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Label_Information__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Lot_Number__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Storage_Requirements__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Max_Exposure_Time__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Label_Expiration_Date__c}"/>   
            </apex:pageBlockSection>
        </apex:pageblock>
        
        <apex:pageblock >
            <apex:pageBlockSection title="Packaging/Labeling Operation" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Packaging_Site__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Site__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Quantity_Required__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Sampling_Requirements__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.CreatedById}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Package_Instructions__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Calculated_Qty_to_be_Prepared__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Randomization__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Randomization_File_Acknowledgement__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.LastModifiedById}"/>   
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
    
    <apex:relatedList list="Parts__r" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="Histories" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="ProcessSteps" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="ActivityHistories" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="OpenActivities" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="AttachedContentDocuments" />
    
    
</apex:page>

 
Hi, I need to export all data from Salesforce. what are all the possible ways?
1. data loader - used to export data from a particular object
2. REST API - from a particular sobject only, data can be extracted.

Is there anyway? 
 
I'm creating approval process in opportunity when engagement_model__c not equal to none which is a picklist field, an email should be sent to users.
im getting the email, but I'm not getting the link. I don't the issue. Help me to solve it.
Hi everyone,

I have a picklist field called Engagement_model__c in Opportunity. it has the values
1.Fixed Bid
2.Time&Material
3.Fix Capacity

If 1 is selected it should display some 5 custom fields and values should be entered, and record should be saved.
Hii Everyone!! I have the requirement of, i need to create a custom checkbox field, formula field and another checkbox field. in formula field, I need to calculate for business days. for example, today i'm creating a case, so the formula field should have the formula to calculate the 5 to 11 business days from case created or updated date. If the first checkbox is false and date field is between 5 and 11 business days, i should write the trigger to make the 2nd checkbox to true. if all these three fields satisfies the condition, an email should be triggered using workflow. help me!!
public class UpdateContactName {
    
    public static void methodTopopulateContact(List<Case> cs){
        String emailField;
        
        List<Case> updateCases=new List<Case>(); //creates a list of case records.
        
        for(Case newCase:cs){
            if(newCase.Profile_received_from_Email__c!=null){ //checks whether the custom field is empty
                emailField = newCase.Profile_received_from_Email__c;
                system.debug('The email field is '+ emailField);
            }
        }
        
        List<Contact> con=[select accountId,Id,email from Contact where email=:emailField]; //query the records from contact
        
        if(con.size()>0){
            for(Case cse:cs){
                cse.contactId=con[0].id;
                cse.accountId=con[0].accountId;
                updateCases.add(cse);
            }
        }
    }
}
 
trigger caseTrigger on Case (before insert,before update) {
    if((trigger.isupdate || trigger.isInsert) && trigger.IsBefore){
        UpdateContactName.methodTopopulateContact(Trigger.new);
    }
}

 
@isTest
public class CaseClassTest {
    
    static TestMethod void MyUnitTest(){
        
        Test.startTest();
        Pagereference tocase = Page.NewVFPage;
        
        Case  testCase = new Case();
        
        testCase.Status='Closed';
        testCase.Reason='Other';
        
        insert testCase;
        
        Test.setCurrentPage(tocase);
        
        tocase.getParameters().put('Id',testCase.id);
        ApexPages.StandardController sc = new ApexPages.standardController(testCase);
        CaseClass  cas = new CaseClass (sc);
        
        test.stopTest();
        
        
    }
}

I'm not getting maximum code coverage.. Help me to sort out this
trigger UpdateStage on Account (after insert, after update, before insert, before Update) {   // Performs Custom actions after Record gets saved.
   
    List<Id> accountId = new List<Id>(); // get the list of all Account's ID to be Updated.
    
    for(Account acc : Trigger.new)
    {
        if(acc.All_Opportunities_Won__c==True)   // Checks if the Condition is True. 
            accountId.add(acc.Id);
    }
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    for(Opportunity opp : [select id, StageName, Amount from Opportunity where AccountId in: accountId AND Amount != 0]) // used to get all records from above ID.
    {
        opp.StageName='Closed-Won';   //Update StageName in Opportunity
        oppsToUpdate.add(opp); 
    }
    
    update oppsToUpdate;   // Update all Opportunity in List.
}

 
global class BatchApex implements Database.Batchable<sObject>{
    
    String query = 'SELECT Id,CLOSED__c, Priority FROM Case';
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Case> cas){
        for(Case c : cas){
            if(c.priority=='High'){
                c.CLOSED__c = TRUE;           
            }
        }
        update cas;
        for(Case cs:cas){
            if(cs.Business_days__c==5){
                cas.add(cs);
                sendmail(); 
            }
        }
        update cas; 
    }
    
    global void finish(Database.BatchableContext BC){     
        
    }    
    
    public void sendmail()
    {
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'iswarya.sekar@excelenciaconsulting.com'} ;
            email.setToAddresses(toAddresses) ;
        email.setPlainTextBody('this is a test mail');
        email.setSubject('New Case Logged');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
    }
}
Its updating CLOSED__c to True, But it is not sending email when Business_days__c==5
 
trigger UpdateStage on Account (after insert, after update, before insert, before Update) {   // Performs Custom actions after Record gets saved.
    DisableTriggers__c ab = DisableTriggers__c.getValues('UpdateStage');
  if(ab.activate_Trigger__c ==TRUE){
    List<Id> accountId = new List<Id>(); // get the list of all Account's ID to be Updated.
    
    for(Account acc : Trigger.new)
    {
        if(acc.All_Opportunities_Won__c==True)   // Checks if the Condition is True. 
            accountId.add(acc.Id);
    }
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    for(Opportunity opp : [select id, StageName, Amount from Opportunity where AccountId in: accountId AND Amount != 0]) // used to get all records from above ID.
    {
        opp.StageName='Closed-Won';   //Update StageName in Opportunity
        oppsToUpdate.add(opp); 
    }
    
    update oppsToUpdate;   // Update all Opportunity in List.
}
}

 
public class updateNameClass{
   // public String updateValue{get;set;}
    public updateNameClass(ApexPages.Standardcontroller controller){
    } 
    public PageReference gotostep2(){
        PageReference pref2=New PageReference('/apex/step2page');
        pref2.setRedirect(True);
        return pref2;
    }
    public List<Opportunity>optyList{set;get;}
    public  Map<String, String>labelToAPIName {set;get;}
    public String fldValue {set;get;}
    public List<Opportunity>optyUpdate{set;get;}
    public updateNameClass(ApexPages.StandardSetcontroller controller){
        this.optyList=(List<Opportunity>)Controller.getRecords() ;
        labelToAPIName = new Map <String, String> ();
        
        Map<String, Schema.SObjectField>fieldsMap = Schema.SObjectType.Opportunity.fields.getMap();
        for (Schema.SObjectField field :fieldsMap.values())
        {
          //  System.debug('label'+field.getDescribe().getLabel()+'*********Api**********'+field.getDescribe().getName());
            labelToAPIName.put(field.getDescribe().getLabel(), field.getDescribe().getName());
        }
    }
    
    public pageReference updateMethod(){
        optyUpdate=new List<opportunity>();
        
        String fld = System.currentPageReference().getParameters().get('fieldName');
        System.debug('fld'+fldValue+'==='+fld); 
        if(labelToAPIName.containsKey(fld)){
            String apiFld=labelToAPIName.get(fld);
            System.debug('api'+apiFld);
            for(opportunity op:optyList){
                Map<String, Object>fieldValueMap = new Map<String, Object>();
                fieldValueMap.put(apiFld,fldValue );
                op.put(apiFld,fldValue);
                optyUpdate.add(op);
            }                         
        } 
        Update(optyUpdate);
        System.debug('optyUpdate'+optyUpdate);
        PageReference pref2=New PageReference('/apex/oppupdatepage');
        pref2.setRedirect(True);
        return pref2;
    }     
}

when i give a new value for a field it should be updated in all records(Mass update records from list view). its updating for string fields but not for other fields like date, boolean, decimal etc. Can anyone help me on this? Thanks in Advance!
when i enter value for amount field, that value should be updated in all records of a list view.
can anyone please help me on this. 
im in urgent. its a client requirement.
HI,

I need to display opportunity fields as dropdown in VF page. can anyone suggest me the idea?
curl "https://xxx.salesforce.com/services/data/v35.0/query/?q=SELECT+Id,+Name,+Phone+FROM+Account" -H "Authorization: Bearer <access token> "



But this only fetching 2000 records. I need all 1Lakhs records to be fetched. is there anyway?
public class PrintPageController {
    Public CPL_Protocols__c cp{get;set;}
    public ID cplid{get;set;} // used to pass values from controller to VF page.
    
    public PrintPageController(ApexPages.StandardController controller) {    // Default Constructor Method to fetch data.
        cplid = apexpages.currentpage().getparameters().get('Id');
        
        if(cplid!=null){
            cp =[select id,ownerId,Study_Protocol_Number__c,Approval_Step_Status__c,Status_Date_Time_Stamp__c,Protocol_Status__c, Labels_Due_Date__c,
                 Number_of_Labels_to_Printed__c,Contact__c,user_email__c,Name,
                 Number_of_Study_Sites__c,Study_Type__c,Treatment_Period__c,Country__c,
                 Study_Phase__c,Study_Protocol_Description__c,No_of_Treatment_Grp__c,Enrollment_Period__c,
                 Study_Duration__c,Dosing_Regimen__c,Primary_Packaging__c,Secondary_Packaging__c,Label_Information__c,
                 Labeling_Lot_Number__c,Storage_Requirements__c,Max_Exposure_Time__c,Label_Expiration_Date__c,
                 Packaging_Site__c,Labeling_Site__c,Quantity_Required__c,Sampling_Requirements__c,CreatedById,Labeling_Package_Instructions__c,
                 Calculated_Qty_to_be_Prepared__c,Randomization__c,Randomization_File_Acknowledgement__c,LastModifiedById
                 from CPL_Protocols__c where id=:cplid]; // using ID, it displays the CPL Fields.
            system.debug('The value of CPL Prtocol is'+cp); // To Find and Resolve problems in execution.
        } 
    }
}





VF page:

<apex:page standardController="CPL_Protocols__c" renderAs="pdf" applyBodyTag="false" docType="html-5.0" standardStylesheets="false" showHeader="false" extensions="PrintPageController">
    
    <apex:form >
        <apex:pageBlock title="CPL Request Information Detail">
            <apex:pageBlockSection title="Status" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.OwnerId}"/>  
                <apex:outputfield value="{!CPL_Protocols__c.Study_Protocol_Number__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Approval_Step_Status__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Status_Date_Time_Stamp__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Protocol_Status__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labels_Due_Date__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Number_of_Labels_to_Printed__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Contact__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.user_email__c}"/>  
            </apex:pageBlockSection> 
        </apex:pageBlock>
        
        
        <apex:pageblock >
            <apex:pageBlockSection title="Study Information" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Name}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Number_of_Study_Sites__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Type__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Treatment_Period__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Country__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Phase__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Protocol_Description__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.No_of_Treatment_Grp__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Enrollment_Period__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Study_Duration__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Dosing_Regimen__c}"/>  
            </apex:pageBlockSection>
        </apex:pageblock>
        
        <apex:pageblock >
            <apex:pageBlockSection title="Product Information" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Primary_Packaging__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Secondary_Packaging__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Label_Information__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Lot_Number__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Storage_Requirements__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Max_Exposure_Time__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Label_Expiration_Date__c}"/>   
            </apex:pageBlockSection>
        </apex:pageblock>
        
        <apex:pageblock >
            <apex:pageBlockSection title="Packaging/Labeling Operation" columns="2">
                <apex:outputfield value="{!CPL_Protocols__c.Packaging_Site__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Site__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Quantity_Required__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Sampling_Requirements__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.CreatedById}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Labeling_Package_Instructions__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Calculated_Qty_to_be_Prepared__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Randomization__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.Randomization_File_Acknowledgement__c}"/> 
                <apex:outputfield value="{!CPL_Protocols__c.LastModifiedById}"/>   
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
    
    <apex:relatedList list="Parts__r" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="Histories" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="ProcessSteps" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="ActivityHistories" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="OpenActivities" />
    <apex:relatedList subject="{!CPL_Protocols__c}" list="AttachedContentDocuments" />
    
    
</apex:page>

 
Hi, I need to export all data from Salesforce. what are all the possible ways?
1. data loader - used to export data from a particular object
2. REST API - from a particular sobject only, data can be extracted.

Is there anyway? 
 
I'm creating approval process in opportunity when engagement_model__c not equal to none which is a picklist field, an email should be sent to users.
im getting the email, but I'm not getting the link. I don't the issue. Help me to solve it.
Hi everyone,

I have a picklist field called Engagement_model__c in Opportunity. it has the values
1.Fixed Bid
2.Time&Material
3.Fix Capacity

If 1 is selected it should display some 5 custom fields and values should be entered, and record should be saved.
public class UpdateContactName {
    
    public static void methodTopopulateContact(List<Case> cs){
        String emailField;
        
        List<Case> updateCases=new List<Case>(); //creates a list of case records.
        
        for(Case newCase:cs){
            if(newCase.Profile_received_from_Email__c!=null){ //checks whether the custom field is empty
                emailField = newCase.Profile_received_from_Email__c;
                system.debug('The email field is '+ emailField);
            }
        }
        
        List<Contact> con=[select accountId,Id,email from Contact where email=:emailField]; //query the records from contact
        
        if(con.size()>0){
            for(Case cse:cs){
                cse.contactId=con[0].id;
                cse.accountId=con[0].accountId;
                updateCases.add(cse);
            }
        }
    }
}
 
trigger caseTrigger on Case (before insert,before update) {
    if((trigger.isupdate || trigger.isInsert) && trigger.IsBefore){
        UpdateContactName.methodTopopulateContact(Trigger.new);
    }
}