• Sonali Bhardwaj
  • SMARTIE
  • 509 Points
  • Member since 2011

  • Chatter
    Feed
  • 19
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 85
    Replies

Hi,

 

I am trying to write the  Trigger code when the status of the case is changed and any other changes in fields with conditional loops for changing the Mail subject.

 

The issue was on trigger that send the same mail subject when i changed the status or changed the iother fields in the case.

 

The following is my code,

trigger caseUpdationMailNotification on Case ( after update) {
    contact relatedCaseContact;
    CaseComment Cscmnt;
    for(case Cases :trigger.new){
    relatedCaseContact = [SELECT Email FROM Contact WHERE Id = :Cases.ContactId];
      Messaging.reserveSingleEmailCapacity(1);
               //Fetch the related case contact.
       Messaging.SingleEmailMessage CaseNotificationmail = new Messaging.SingleEmailMessage();  
       CaseNotificationmail.setToAddresses(new List<String> { relatedCaseContact.Email });
       CaseNotificationmail.setReplyTo('ambigaraman@gmail.com');
       CaseNotificationmail.setSenderDisplayName('Salesforce Support');            
      
	  If(Cases.Status =='Working'){      
       CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to working. '+'Case Number:' + Cases.CaseNumber);
       CaseNotificationmail.setPlainTextBody('Your case Status: ' + Cases.CaseNumber +'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);}
       
  If(Cases.Status =='Escalated'){          
   
    CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to Escalated. '+ 'Case Number:' +Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case Status: ' + Cases.CaseNumber +' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    }   
    
 If(Cases.Status =='closed'){           
    
    CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to closed. '+ 'Case Number:' +Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case Status:' + Cases.CaseNumber +' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    }     
else{  
    CaseNotificationmail.setSubject(' Case  updation : ' + 'Case Number:'+ Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case : ' + ' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    } 
	
	
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { CaseNotificationmail });
 }
}

 If i use 'elseif', It again send the email with subject for status changed,

 

Can anyone help me to write the trigger that send the mail that send when we change the status only. or there is only changes in other fields(not in status) of the case?

 

Thanks & Regards.,

Ambiga

 

Hi to all,

 

I have made some code changes in 2 apex classes, when i deploying these two apex classes, it throughs an error like this

: Average Test Coverage across all Apex classes and Triggers is 69%, atleast 75% test coverage is required.

 

when i run those 2 test classes, its test coverage is 84% and 86%.

 

I have deployd with change sets and also i try with Eclipse, getting the same error.

 

Please help me on this error, colud you please suggest any ideas or suggestons it will be greatly apriciated.

 

 

Thanking You in Advance. 

  • August 07, 2013
  • Like
  • 0

Hii evryone i already asked this  question but i didnt got any answer from anybody...again i have serious issue with this topic.....if anyone understands please  tell me your solution.....i will  breifly  clearly explain my task understand step by step...

 

 

 

1)When we click Home  and scroll down we  have  "My Task" when we click new and we create  Task.  when we click new we ll see  fields , in that we   have   'Subject' , and  'Comments'  fields also. let it put aside.

 

2) click contacts , when we open any  existed contact  record  in below we will found  "Activity History"block in that we have  "send an email button"...

 

so  now  when i  click "send an email" button  the email page will opened with appropriate contact....and  we will fill details like  cc,BCC, Subject,Body  in the  email page. and we click  'send'  button to send email.

 

Now  the Requirement  is  when i click the  send button , a  new Task should need to create automatically (In first step it is manually)  and  Task  subject  is  populated by  email subject and  Task  comments  is  populated by  email Body.

 

How  should write  trigger for this...

 

i  found that  there are  no  email  fields are existed like  emails (subject , body ,cc , BCC  because it is standard and designed by salesforce.) so how should i know the fields apis name. but we have Task fields  like  subject,comments in Customize ---> Activities--> Task feilds.

 

can we  write trigger  between 2  objects. (because contacts email data need to save on Task.they are two diff objs)...

Hi,

 

I am new to Salesforce. Please help me in implementing following

 

In my Apex code, i have name of selected object in a Variable
I need a piece of code which returns name of the fields which are external ids in that selected object.

 

 

  • June 28, 2013
  • Like
  • 0

Accounts is a custom object.i have to retrieve the  account type on the basis of Name.
I am able to retrieve the id and i'm  getting  account type in debug. But, it isnt displayed in the VF page.
Please have a look at the code..

 

Given below is the code of Class and VF page

<apex:page controller="SearchByName">
 <apex:form >
  <apex:outputLabel style="font-weight:bold;" value="Search By Name" ></apex:outputLabel>
        <apex:inputText value="{!textData}"/> 
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs" status="status"/>
 </apex:form>
 <!------Doesnt print the first name and account type------->
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Accounts}" var="c" >
  <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:outputField value="{!c.First_Name__c}" />
  </apex:column>
  <apex:column >
                <apex:facet name="header">Account Type</apex:facet>
                <apex:outputField value="{!c.Account_Type__c}" />
  </apex:column>

     
  </apex:pageBlockTable>
  </apex:pageBlock>
  
     <!------------- Getting the value of var "c"------------>
   <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="searching...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    
                    <apex:dataList value="{!Accounts}" var="c">a:{!c}</apex:dataList>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
 </apex:page>

 

public class SearchByName
{
 List<Account__c> Accounts;
private String textdata = null;

    public String getTextData() { return textdata; }
    
    public void setTextData(String data) { textdata = data; }
    
        
        
        public void search(){            
           
            Accounts = Database.query('SELECT First_Name__c,Account_Type__c  FROM Account__c where First_Name__c = :textdata');
            system.debug('Accounts>>>>'+Accounts);
       }    
        public List<Account__c> getAccounts() {
                
                return Accounts;
        }
        
       
}

 

  • June 28, 2013
  • Like
  • 0

I'm tring to optimize the code below.

I'm looking for a structure where i can put the picklist's values and after (with just a condition) i want check the condition for all the values in the structure.

if ((lead.Status.trim()=='Archived' || lead.Status.trim()=='False'||lead.Status.trim()=='Lead - Never'))

 

should be like this:

structure=['Archived','False','Lead - Never']; 
if ((lead.Status.trim()==structure))

 

I can not find anything, do you know how i can do this?

Thanks in advantage for any advice.

Br

  • June 28, 2013
  • Like
  • 0

Double growthRate  = LifeInsuranceInterest__c.getInstance(description).Rate__c;

 

I am getting an error here, plz tell me what this error means...

 

ErrorError: Compile Error: Not of type Custom Settings at line 545 column 29

Hi all,

 

I have a visualforce page that creates a new lead, however, how can I get it to add the new lead to a campaign, like a web-to-lead form does.  In a web-to-lead form you would use campaign_id and member_status but that doesn't work in the apex.  I also have a primary_campaign_id__c field in the lead so could I use that and if so how?

 

Here is the apex code:

 

public class Reserve {

    public Lead lead {get; private set;}

    public String company {get; set;} 
    public String email {get; set;}
    public String phone {get; set;}
    public String firstName {get; set;}
    public String lastName {get; set;}
    public String title {get; set;}

    public String getName() {
        return 'Reserve';
    }

    // save button is clicked
    public PageReference save() {
        
        Lead l = new Lead(
        OwnerId = '00GE0000000hCBH',
        LeadSource = 'Reserve',
        FirstName = firstName,
        LastName = lastName,
        Email = email,
        Phone = phone,
        Title = title,
        Company = company,
        List_Assignment__c = 'Reserve',
        Primary_Campaign_ID__c = '701E0000000TwCG'
        );
        
       
    try {
      insert l; // inserts the new record into the database
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'Error adding Reserve List.'));
      return null;
    }
        return Page.confirmationReserveEntry;      
 
    } 
  
}

Thanks

Kev

Hi,

 

I wrote a trigger that serves to update a custom field on an object. The field actually gets updated with the change in price of the item. Now am kind of stuck with it if I use the before update trigger, it shows the second last change in the price. I cannot use the After update as record gets locked and I cannot update the field value. Below is the trigger code:

 

trigger TrackPRICEupdate on pb__InventoryItem__c(before update) {
pb__InventoryItem__History invh = new pb__InventoryItem__History();
	for(pb__InventoryItem__c inv: trigger.new){
		invh = [Select NEWVALUE, FIELD, OLDVALUE, CREATEDDATE, PARENTID from pb__InventoryItem__History
		where PARENTID = :inv.id and FIELD = 'pb__PurchaseListPrice__c' 
		order by CREATEDDATE DESC LIMIT 1];
		
		
		if(invh.oldvalue <> null && invh.newvalue <> null)
		{
		 string a = string.valueof(invh.oldvalue);
		 string b = string.valueof(invh.newvalue);
		 decimal old = decimal.valueof(a);
		 decimal newv = decimal.valueof(b);
		 inv.price_change__c = newv - old;
		}
		//update inv;
	}	
}

 Anyone can help?

Hi,

 

I've got a really simple trigger here that's giving me a little grief.  I've got child records off Opportunities called "Opportunity Allocations".  When an opportunity is created, we assume the allocation to the owner is at 100%.  Later, we might allocate other percentages to the owner, plus members of the sales team.

 

After insert on Opportunity, I create a row in Opportunity_Allocation__c, supplying OpportunityId and Opportunity.OwnerId.  For some reason I can't figure out, the Opportunity.OwnerId field won't populate on the child record.

 

The child record field is called "Sales_Team_Member__c and I've set it up as a lookup to User.  So I should be able to simply populate OwnerId into it or any other primary key for any other record in User object.  But it comes up null when the trigger fires.

 

So I decided to add a text field in called "STM" and I also put Opportunity.OwnerId in that field.  That works.

 

Here's the code.  The only bit that doesn't work properly is the beginning, inside the first if.   The rest of the trigger works as it should.  The rest of the trigger reassigns the owner's share of allocation every time the owner of the opportunity works.

 

I expected to have more trouble with the latter half of the code but that works.  The trouble's in the first 18 or so lines.

 

 

trigger insUpdOpportunity on Opportunity (after insert, after update) {
	
	List<Opportunity_Allocation__c> oaList = new List<Opportunity_Allocation__c>();
	
	if(Trigger.isInsert) {
		for (Opportunity o : trigger.new) {
			
			Opportunity_Allocation__c oa = new Opportunity_Allocation__c (
				Opportunity__c = o.Id,
				IsOwner__c = true,
				Percentage_Of_Revenue__c = 100,
				Region__c = 'XXX',
				Sales_Team_Member__c = o.OwnerId,
				STM_txt__c = o.OwnerId			
				);
			
			system.debug('this is oa:' + oa);		
			oaList.add(oa);			
		}
		
		insert oaList;
	
	
	}  // end if

	
	if(Trigger.isUpdate) {
		Opportunity[] oldOpp = trigger.old;
		Opportunity[] newOpp = trigger.new;
		

		// build the map of opp to new opp owner
		map<Id, Id> oppMap = new map<Id, Id>();		

		for (Integer i = 0; i < newOpp.size(); i++ ) {
			
			if (oldOpp[i].OwnerId != newOpp[i].OwnerId) {
				oppMap.put(newOpp[i].Id, newOpp[i].OwnerId)	;
			}

		}

		// build the list of opportunity allocations to modify
		
		oaList = [select Id,Opportunity__c, Sales_Team_Member__c 
					from Opportunity_Allocation__c
					where Opportunity__c in :Trigger.newMap.keyset() 
					 and IsOwner__c = true];


		// loop over the list and change the Sales_Team_Member 
							
		for (Opportunity_Allocation__c oa : oaList) {
				 
				oa.Sales_Team_Member__c = oppMap.get(oa.Opportunity__c);
		}

	//upsert the changed values (if any)
	if (oaList.size() > 0) 
		upsert oaList;
	
	}  // end if


}

 

 

 

What am I doing wrong?

 

Thanks!!

Can anyone tell me, help me, why the mainimage not rerenders?

The mainImage renders in a  datatable component but not in a repeat component.

Use of repeat component is because i want a list of images shown horizontally instead of vertically.

 

The VisualForce page.:

 

 

<"abc__c"extensions="cntabcImageBrowser">

<apex:form>

    <apex:pageBlock>

       <apex:outputpanelid="mainImage">

           <apex:Imagevalue="{!theImage}"title="{!theImage}"height="135px"/>

       </apex:outputpanel>

    <br/>

    <h2>Images in table form as they will be displayed the page</h2>

    <br/>

    <apex:repeatvalue="{!abcList}"var="stocksetImage">

    <apex:Image value="{!abcImage}" title="{!abcImage}" width="49px"/>

    <apex:actionSupport action="{!makeMainImage}" event="onmouseover" rerender="mainImage">     

       <apex:param name="ImageID" value="{!abcImage}" />

    </apex:actionsupport>     </apex:repeat> <!-- the list of images in a simple table -->    

    <br/>  

    <br/>

    <br/>  

    </apex:page>

</apex:pageBlock>

</apex:form>

 

 

Controller:

 

 

public String theImage {get;set;}

 

// action on Page image Generiek

    public PageReference makeMainImage(){

          theImage = ApexPages.CurrentPage().getParameters().get('ImageID');

    returnnull;

 

}

 

Thanks in front

 

Paul

  • June 01, 2011
  • Like
  • 0

 

<!-- For this example to render properly, you must associate the Visualforce page 
with a valid account record in the URL. 
For example, if 001D000000IRt53 is the account ID, the resulting URL should be: 
https://Salesforce_instance/apex/myPage?id=001D000000IRt53
See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
         
<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.type}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 This is a code for the standard Object but If I want to insert/reference any custom object then how can i do that ?

I tried this things as I putted {!CustomObjectName__c.CustomFieldName__c} as value of the input field...

Regards....

 

public id dummy;

public pagereference somemethod()

{

try{

 sometype obj=[select id from sometype where id=: dummy];

}catch(e)

{

  apexpage.addMessage();

}

return null;

}

testMethod()

{

  set dummy to null;

  call to somemethod();

}

 

Hi there,

When save, the test stop at the call to somemethod() with error:

System.QueryException: List has no rows for assignment to SObject.

But this error is supposed to be catched in the method itself.

Any idea appriciated?

 

 

Hi,

 

I have been revising my trigger code as I had DML Insert statements inside my loop. I created a list and brought the DML statements outside of loop, but have ran into another issue as a result.  I need to create a contact and link the contact to the Bankruptcy_Judgements_Liens_Report__r custom object through the BJVLAgencyContact.ID lookup field.  When I insert outside of the loop, the actual contact ID is not captured since its not inserted.

 

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{
Set<ID> accID = new Set<ID>();
//map to contain Con_Service_Task_Request__c record's id as key and it's master Account record's ID as value
Map<ID, ID> mapST_Account = new Map<ID, ID>();
Map<ID, ID> mapPrincipalAcctCont = new Map<ID, ID>();
Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();

List <Contact> listBJLVAgencyContact = new List<Contact>();
List <Bankruptcy_Judgements_Liens_Report__c> listBJLV = new 


for(Con_Service_Task_Request__c ST : trigger.new){
         //This "Con_Service_Task_Request__c" should be API Name of Master Detail relationship with the Account 
         accID.add(ST.Account__c);
         mapST_Account.put(ST.id , ST.Account__c);
         
         Contact Principalcontact=[SELECT ID FROM Contact WHERE AccountId = : ST.Account__c AND Contact_Type__c = 'Acct Principal Contact' limit 1];
         mapPrincipalAcctCont.put(ST.id, Principalcontact.ID); 
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID FROM Trade_Reference_Report__c WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c limit 3]; 
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
    }
    
Map<Id,List<Account>> records = new Map<Id,List<Account>>();
for(Account a : [SELECT id , 
(select id from Bankruptcy_Judgements_Liens_Report__r) 

FROM Account 
WHERE id in : accID]) {
    if(!records.containsKey(a.id))  {
        records.put(a.id , new List<Account>());
    }
    records.get(a.id).add(a);   
}   

for (Con_Service_Task_Request__c ST : Trigger.new) {

//INSERT NEW BJLV RECORD IF REQUIRED AND DOES NOT YET EXIST 
if (records.get(mapST_Account.get(ST.id)).get(0).Bankruptcy_Judgements_Liens_Report__r.Size()  == 0) 

Contact BJLVAgencyContact = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'BJLV Agency', LastName = 'Enter Last Name');
 listBJLVAgencyContact.add(BJLVAgencyContact);

Bankruptcy_Judgements_Liens_Report__c BJLV = new Bankruptcy_Judgements_Liens_Report__c(Account__c = ST.Account__c , BJLV_Agency_Contact__c = BJLVAgencyContact.ID ); //BJVLAgencyContact.ID does not exist at this stage since Insert //outside of the loop now   
 listBJLV.add(BJLV);
 
}


}
insert listBJLVAgencyContact;
insert listBJLV; //Does not link to Contact on Insert. How would I get it to link?
}

 

 

  • June 01, 2011
  • Like
  • 0

On the below test code I am covering 53% and have an error that says the following:

 

 

TestQuoteExt.basicAttachTest

	System.QueryException: List has no rows for assignment to 
SObject	

Class.quoteExt.attachQuote: line 17, column 23 Class.TestQuoteExt.basicAttachTest: line 42, column 32 External entry point

 

 

I am running agains a brick wall. How to I solve this error in the test class?

 

Test Class:

 

@IsTest private class TestQuoteExt {

    /* This is a basic test which simulates the primary positive case for the 
       save method in the quoteExt class. */
    public static testmethod void basicSaveTest() {

        /* Construct the standard controller for quote. */
        ApexPages.StandardController con = new ApexPages.StandardController(new quote());

        /* Switch to runtime context */
        Test.startTest();

        /* Construct the quoteExt class */
        QuoteExt ext = new QuoteExt(con);


        /* Switch back to test context */
        Test.stopTest();
    }

    /* This is a basic test which simulates the primary positive case for the 
       attachQuote method in the quoteExt class. */
    public static testmethod void basicAttachTest() {

        /* Construct the standard controller for quote. */
        ApexPages.StandardController con = new ApexPages.StandardController(new Quote());

        /* Construct the quoteExt class */
        QuoteExt ext = new QuoteExt(con);

        /* Call save on the ext */
        // ext.save();       

        /* Set the extension quote object using the id on the controller. */
        ext.q = new quote(id = con.getId());  

        /* Switch to runtime context */
        Test.startTest();

        /* Simulate the button invocation of the attachQuote action method 
           on the extension. */
        PageReference result = ext.attachQuote();

         /* Switch back to test context */
        Test.stopTest();

        /* Verify the navigation outcome is as expected */
        System.assertEquals(result.getUrl(), con.view().getUrl());

        /* Verify the attachment was created. */
       System.assert([select name from attachment where parentid =:con.getId()].name!= null);
    }


    /* This setup method will create an opportunity with line items and a primary
       contact role for use in various tests. */
    private static Opportunity setupTestOpportunity() {

        /* Create an account */
        Account a = new Account();
        a.name    = 'TEST';
        Database.insert(a);

        /* Get the standard pricebook. There must be a standard pricebook already 
           in the target org.  */
        Pricebook2 pb = [select name, isactive from Pricebook2 where IsStandard = true limit 1];

        if(!pb.isactive) {
            pb.isactive = true;
            Database.update(pb);
        }

        /* Get a valid stage name */
        OpportunityStage stage = [select MasterLabel from OpportunityStage limit 1];

        /* Setup a basic opportunity */
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST';
        o.AccountId    = a.id;
        o.CloseDate    = Date.today();
        o.StageName    = stage.masterlabel;
        o.Pricebook2Id = pb.id;

        /* Create the opportunity */
        Database.insert(o);

        /* Setup a basic Template*/
        PDF_Template__c pd  = new PDF_Template__c();
        pd.Name         = 'English';
        pd.Template_Address__c = 'apex/English';
        
        /* Create the Template */
        Database.insert(pd);        

        /* Setup a basic quote*/
        Quote q  = new Quote();
        q.Name         = 'TEST';
        q.OpportunityId    = o.id;
        q.PDF_Template__c = pd.id;


        /* Create the opportunity */
        Database.insert(q);

        /* Create a contact */
        Contact c   = new Contact();
        c.lastname  = 'LASTNAME';
        c.firstname = 'FIRSTNAME';

        Database.insert(c);

        /* Create the opportunity contact role */
        OpportunityContactRole r = new OpportunityContactRole();
        r.ContactId     = c.id;
        r.OpportunityId = o.id;
        r.IsPrimary     = true;
        r.role          = 'ROLE';

        Database.insert(r);

        /* Create a product2 */
        Product2 p = new Product2();
        p.Name     = 'TEST';

        Database.insert(p);

        /* Create a pricebook entry. */
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = pb.id;
        pbe.Product2Id   = p.id;
        pbe.IsActive     = true;
        pbe.UnitPrice    = 1;

        Database.insert(pbe);

        /* Create a line item */
        OpportunityLineItem i = new OpportunityLineItem();
        i.opportunityId       = o.id;
        i.pricebookentryid    = pbe.id;
        i.quantity            = 1;
        i.unitprice           = 1;

        Database.insert(i);

        /* Set up the opportunity with the related records */
        r.Contact        = c;
        r.Opportunity    = o;
        o.Account        = a;
        i.Opportunity    = o;
        pbe.Product2     = p;
        pbe.Pricebook2   = pb;
        i.PricebookEntry = pbe;

        return o;
    }
}

 

 

Class:

 

 

    ApexPages.StandardController controller;

    public Quote q {get;set;}

    public quoteExt (ApexPages.StandardController c) {
        controller = c;
        q          = (Quote) c.getRecord();

    }

public PageReference attachQuote() {

        PageReference pdfPage;

        Quote quote = [select id, PDF_Template__r.id, PDF_Template__c, PDF_Template__r.Template_Address__c from Quote 
                where id = :ApexPages.currentPage().getParameters().get('id') ];
   
        if(Quote.PDF_Template__c != null) {
            pdfPage = new PageReference('/apex/' + quote.PDF_Template__r.Template_Address__c);
        }
         
        pdfPage.getParameters().put('id',q.id);
        
        Blob pdfBlob = pdfPage.getContentAsPDF();
        
        QuoteDocument a = new QuoteDocument(quoteId= q.id, Document = pdfBlob);
        
        insert a;
        
        return controller.view();
    }
}

 

Thank you

 

hi

 

Here is my visualforce page:

 

 

<apex:page standardController="Contact" extensions="CreditTransactions" >
<apex:form >
 <apex:pageBlock title="Payment Methods" >
<apex:pagemessages />
<apex:pageBlockTable value="{!Results}" var="transaction" title="Payment Methods" >
<apex:inputhidden value="{!transaction.tranId}" id="transactid"/>
  <apex:column headerValue="Date Last Used" value="{!transaction.tDate2}"/> 
    <apex:column headerValue="Last 4 digits" value="{!transaction.cardnum}"/> 
    <apex:column headerValue="Expiration Date" value="{!transaction.cardexp}" id="expired"/> 
  <apex:column >
    <apex:commandButton action="{!Vterminal}" value="Virtual Terminal" reRender="hiddenblock">
               <apex:param name="para" value="{!transaction.tranId}" assignTo="{!para}"></apex:param>
               <apex:param name="expired" value="{!transaction.cardexp}" assignTo="{!expired}"></apex:param>                               </apex:commandButton>
    </apex:column>
   
</apex:pageBlockTable>
 <apex:outputPanel id="hiddenblock">
 </apex:outputPanel>
  </apex:pageBlock>
  </apex:form>
 <apex:detail />
</apex:page>
I have added <apex:pageMessages/> to the page. and here is my code when I click the button.
 public PageReference Vterminal() 
    {
            
    System.debug('expired param valueeee'+expired);
    expmonth = Integer.valueOf(expired.substring(0,2));
    expyear = Integer.valueOf(expired.substring(3,7));
    expmonthdate = Date.newInstance(expyear, expmonth,01 );
    System.debug('expired monthdate valueeee'+expmonthdate);
      p=new PageReference('/apex/VirtualTerminal?id='+para);
    if(expmonthdate>System.Today()){
      
        return p;
        }else{
   
       ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'Card Expired');  
         ApexPages.addMessage(errMsg);
        }
        return null;
    }
In the debug logs error message is displaying but in the visual force page it is not showing.
Please help.

 

Hello ,

 

I was trying to change the value of the Leadstatus in After Insert.

 

Having changed the status of a set of leads in one method i made a call to the next one. 

 

But this does not work. I sends out an Exception: Reacord is read only

 

Can some one please help me on this.

 

 public static void afterInsertLeadTrigger(List<Lead> newLeads) {
        // Process Leads after Insert Process
        system.debug('Check IsError:' + isError);
        if(!isError){
            method1(newLeads);
            method2(newLeads);
        }else{
            isError = false;
        }
    }

 

Thanks

Bidun

  • May 30, 2011
  • Like
  • 0

How to update the records directly from email to salesforce related object not by using tomcat or any other server just it should done by using only email services... 

What things should be keep in mind while deploying project or single program from Sandbox to Production environment ?

 

I have created one program & it is executing fine in sandboox environment but it is running in production environment & showing me error of code test coverage is of 15% & it must be atleast 75%.

 

The code is as follow...

<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectRadio value="{!country}">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio><p/>
            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
     </apex:form>
     <apex:outputPanel id="out">
          <apex:actionstatus id="status" startText="testing..."> 
             <apex:facet name="stop"> 
               <apex:outputPanel> 
                  <p>You have selected:</p> 
                 <apex:outputText value="{!country}"/> 
              </apex:outputPanel> 
            </apex:facet> 
          </apex:actionstatus> 
     </apex:outputPanel> 
</apex:page>
            
/*** Controller ***/
public class sampleCon {
    String country = null;
         
    public PageReference test() {
        return null;
    }
                
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('US','US')); 
        options.add(new SelectOption('CANADA','Canada')); 
        options.add(new SelectOption('MEXICO','Mexico')); return options; 
    }
                   
    public String getCountry() {
        return country;
    }
                    
    public void setCountry(String country) { this.country = country; }
}

 Now there are two files & Controller : SampleCon & other is VFPage : RadioButton...I uploaded both the files from outbound change set of sandbox environment & I deployed it from inbound change set of production environment but getting test coverage & action gets failed.

 

Please help me...

There is one system, which has exposed their API through DLL. I want to use that DLL in Salesforce.

For example, DLL have one class and has one function under it called login. I want to use this function in Salesforce.

 

How can I achieve this? Is their any way I can convert DLL to WSDL and import into Salesforce, or any other way?



There is one system, which has exposed their API through DLL. I want to use that DLL in Salesforce.

For example, DLL have one class and has one function under it called login. I want to use this function in Salesforce Apex.

 

How can I achieve this? Is their any way I can convert DLL to WSDL and import into Salesforce, or any other way?



There is one system, which has exposed their API through DLL. I want to use that DLL in Salesforce.

For example, DLL have one class and has one function under it called login. I want to use this function in Salesforce.

 

How can I achieve this? Is their any way I can convert DLL to WSDL and import into Salesforce, or any other way?

I have some requirement, I need to parse CSV in Apex through RegEx.

I am able to parse it successfully using some string functions (split, substring, etc.) but I want to parse it through RegEx.

 

Could any one please help me on RegEx for CSV parsing?

Hi,

 

I am trying to write the  Trigger code when the status of the case is changed and any other changes in fields with conditional loops for changing the Mail subject.

 

The issue was on trigger that send the same mail subject when i changed the status or changed the iother fields in the case.

 

The following is my code,

trigger caseUpdationMailNotification on Case ( after update) {
    contact relatedCaseContact;
    CaseComment Cscmnt;
    for(case Cases :trigger.new){
    relatedCaseContact = [SELECT Email FROM Contact WHERE Id = :Cases.ContactId];
      Messaging.reserveSingleEmailCapacity(1);
               //Fetch the related case contact.
       Messaging.SingleEmailMessage CaseNotificationmail = new Messaging.SingleEmailMessage();  
       CaseNotificationmail.setToAddresses(new List<String> { relatedCaseContact.Email });
       CaseNotificationmail.setReplyTo('ambigaraman@gmail.com');
       CaseNotificationmail.setSenderDisplayName('Salesforce Support');            
      
	  If(Cases.Status =='Working'){      
       CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to working. '+'Case Number:' + Cases.CaseNumber);
       CaseNotificationmail.setPlainTextBody('Your case Status: ' + Cases.CaseNumber +'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);}
       
  If(Cases.Status =='Escalated'){          
   
    CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to Escalated. '+ 'Case Number:' +Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case Status: ' + Cases.CaseNumber +' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    }   
    
 If(Cases.Status =='closed'){           
    
    CaseNotificationmail.setSubject(' Case Status updation : ' +'Changed to closed. '+ 'Case Number:' +Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case Status:' + Cases.CaseNumber +' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    }     
else{  
    CaseNotificationmail.setSubject(' Case  updation : ' + 'Case Number:'+ Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case : ' + ' has been updated.'+'To view your case <a href=https://na1.salesforce.com/'+Cases.Id);
    } 
	
	
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { CaseNotificationmail });
 }
}

 If i use 'elseif', It again send the email with subject for status changed,

 

Can anyone help me to write the trigger that send the mail that send when we change the status only. or there is only changes in other fields(not in status) of the case?

 

Thanks & Regards.,

Ambiga

 

Hi,

 

We usually use map in triggers and classes. Can someone help me to understand in which object we should use map?

 

Suppose: I have 2 objects:

 object1

object2

Based upon crtain condition of objecct1, the certain field of object2 changes.

So,  in which object should we use map?

 

Please help.

  • August 20, 2013
  • Like
  • 0

Hi guys,

I need help to update a custom field. I have two custom objects A and B with mater details relationship and both have education progress field. Every time When a new record is added to object B , i want to insert objects B’s (education progress fields) value into Object A’s education progress field and it will concatenate values with comma. Object A have one-to-many relationship with Object B.


Please suggest best way to achieve this.

Thanks in advance.

Regards,

In the past few weeks I have put together a number of visualforce chart based pages with dynamic controls and everything, all with no problem. Suddenly one won't render the actual chart. After hours of trying to debug the controller, I slowly paired everything back until I am now pretty sure the problem in in my visualforce code.

 

But I can't see the mistake.

 

Anyone able to keep me out of the big white house with padded walls?

 

Visualforce 
===============================
<apex:page controller="TEST_TableLine_ActivitySummary" >
    <apex:form > 
    <apex:pageBlock title="Test">
    <!-- The Chart -->
    <apex:pageBlockSection >
    Begin
    <apex:chart height="800"  width="1200"  data="{!teDat}" id="actCh">
        <apex:legend position="right"/>
        <apex:axis type="Numeric" position="left" fields="rowAnum, rowBnum" title="Meetings Calls"/>
        <apex:axis type="Category" position="bottom" fields="pLab" title="Date" >
            <apex:chartLabel rotate="315"/>
        </apex:axis>
        <apex:lineSeries title="Jo" axis="left" xField="pLab" yField="rowAnum" strokeColor="#190710" strokeWidth="2" markerFill="#190710" markerType="cross" markerSize="4"/>
        <apex:lineSeries title="not Jo" axis="left" xField="pLab" yField="rowBnum" strokeColor="#BBAACC" strokeWidth="2" markerFill="#BBAACC" markerType="cross" markerSize="4" />
    </apex:chart>
    End
    <apex:dataTable value="{!teDat}" var="a" >
        <apex:column headerValue="Period" value="{!a.pLab}"/>
        <apex:column headerValue="NumA" value="{!a.rowAnum}"/>
        <apex:column headerValue="NumB" value="{!a.rowBnum}"/>
    </apex:dataTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>  
</apex:page>

Even here, the "Begin", "End" and the dataTable are things I added back in just to see if the render (they do). If I remove them, all I get is the page title. The table also shows the data is correct.

 

In case it helps, although I am pretty certain the error is not here, this is my test controller:

 

Controller 
===============================
public with sharing class TEST_TableLine_ActivitySummary {

    public List<ActivityGraph> teDat;
    
    //Constructor
    public TEST_TableLine_ActivitySummary() {
     
    }
    
    // -- The Activity Graph
    public List<ActivityGraph> getteDat() {
        
       List<ActivityGraph> activityFinalGraph = new List<ActivityGraph>();
        
        activityFinalGraph.add(new ActivityGraph('Day 1'));
        activityFinalGraph[0].addUserMeetings(0,5);
        activityFinalGraph[0].addUserMeetings(1,9);
        activityFinalGraph.add(new ActivityGraph('Day 2'));
        activityFinalGraph[1].addUserMeetings(0,8);
        activityFinalGraph[1].addUserMeetings(1,3);
        

System.debug('aFG: '+activityFinalGraph);
        return activityFinalGraph;
    }

    
    public class ActivityGraph
    {
        //STRUCT   -- Going to assume no team will ever have more than 13 people
        public String pLab { get; set; }
        public Integer rowAnum { get; set; } 
        public Integer rowBnum { get; set; } 

        //Constructors
        public ActivityGraph(String pl) 
        {
                   pLab = pl;
                rowAnum = 0;
                rowBnum = 0;
        }
        
        //Utility Methods
        public void addUserMeetings(Integer row, Integer nMtg) 
        {
            if(row == 0)  rowAnum = nMtg;
            if(row == 1)  rowBnum = nMtg;
        }
    }
}

Again the System.debug call shows that the data being returned is correct.

 

What is wrong with my chart? I am assuming it is staring me in the face but it is alluding me.

 

Regards

MellowRen

Hi

 

I have what I thought would be a simple thing but can’t work out how, or if, Visualforce charts can do it.

 

I have a set of data derived in Apex code which has:

 

  1. User Name
  2. Category
  3. Number (in category)

… and would like to graph it as such (using X, Y, Z to represent colour bars):

 

  5                             Legend
N 4   XY         Z              User X
u 3   XY         Z      Y       User Y
m 2   XYZ       YZ     XY       User Z
  1   XYZ      XYZ     XYZ
      Good     Bad     Ugly
           Category

The problem I have is that both the number of users and number of categories is not fixed (they are determined in the controller's Apex code). I can ensure every User has a value for every category (even if it is 0) so that is not a problem. In the sparse examples in the docs, I can only see how to do it when the number of categories is indetermined. They show data structures as such:

 

graph data {

    user_x

    user_y

    user_z

    category_label

    number

}

 

But since I don't know how many users I'll have (nor their names) until the code has run, I am not sure how to put the data nor the visualforce code together. I tried experimenting with things like:

 

<apex:chart height="300" width="700" data="{!activityGraph}" id="actChart">
    <apex:legend position="right"/>
    <apex:axis type="Numeric" position="left" fields="numberM" title="# Ms"/>
    <apex:axis type="Category" position="bottom" fields="catLabel" />
    <apex:barSeries title="{!activityGraph[0].userName}" axis="left" xField="catLabel" yField="{!activityGraph[0].numberM}" orientation="vertical"/>
</apex:chart>

…with the hope of embedding the barSeries into a <apex:repeat> loop. But that doesn't work.

 

I am really hoping that I am missing something simple here. Anyone got any ideas?

 

Regards

MellowRen

<apex:page standardController="Application__c" extensions="app">
    <h1>Application Form</h1>
   
    <apex:form >
        <apex:pageMessages id="error"/>
        <apex:pageBlock >
        <apex:pageBlockSection title="Information">
       
        <apex:inputText value="{!Application__c.Name}"/>
        <apex:inputText value="{!Application__c.Candidate_Name__c}"/>
        <apex:inputText value="{!Application__c.Age__c}"/>
        <apex:inputText value="{!Application__c.Address__c}"/>
        <apex:inputText value="{!Application__c.Contact_Number__c}"/>
        </apex:pageBlockSection>
         <apex:commandButton value="Review" />


      </apex:pageBlock>
    </apex:form>

    </apex:page>

Hi to all,

 

I have made some code changes in 2 apex classes, when i deploying these two apex classes, it throughs an error like this

: Average Test Coverage across all Apex classes and Triggers is 69%, atleast 75% test coverage is required.

 

when i run those 2 test classes, its test coverage is 84% and 86%.

 

I have deployd with change sets and also i try with Eclipse, getting the same error.

 

Please help me on this error, colud you please suggest any ideas or suggestons it will be greatly apriciated.

 

 

Thanking You in Advance. 

  • August 07, 2013
  • Like
  • 0

Hi,

 

Can I know how to refresh the entire Visual force or Part of the page when a component is modified(i.e. when a command link action is performed by the component).

 

Thanks & Regards

Hii evryone i already asked this  question but i didnt got any answer from anybody...again i have serious issue with this topic.....if anyone understands please  tell me your solution.....i will  breifly  clearly explain my task understand step by step...

 

 

 

1)When we click Home  and scroll down we  have  "My Task" when we click new and we create  Task.  when we click new we ll see  fields , in that we   have   'Subject' , and  'Comments'  fields also. let it put aside.

 

2) click contacts , when we open any  existed contact  record  in below we will found  "Activity History"block in that we have  "send an email button"...

 

so  now  when i  click "send an email" button  the email page will opened with appropriate contact....and  we will fill details like  cc,BCC, Subject,Body  in the  email page. and we click  'send'  button to send email.

 

Now  the Requirement  is  when i click the  send button , a  new Task should need to create automatically (In first step it is manually)  and  Task  subject  is  populated by  email subject and  Task  comments  is  populated by  email Body.

 

How  should write  trigger for this...

 

i  found that  there are  no  email  fields are existed like  emails (subject , body ,cc , BCC  because it is standard and designed by salesforce.) so how should i know the fields apis name. but we have Task fields  like  subject,comments in Customize ---> Activities--> Task feilds.

 

can we  write trigger  between 2  objects. (because contacts email data need to save on Task.they are two diff objs)...

How could i write a test class for a controller with out  its constructor class??

 

example 1)public class convertToCLA {
List<Contact> contacts;
List<Lead> leads;
List<Account> accounts;

public void convertType(Integer phoneNumber) {
List<List<sObject>> results = [FIND '4155557000'
IN Phone FIELDS
RETURNING Contact(Id, Phone, FirstName, LastName),
Lead(Id, Phone, FirstName, LastName), Account(Id, Phone, Name)];
sObject[] records = ((List<sObject>)results[0]);

if (!records.isEmpty()) {
for (Integer i = 0; i < records.size(); i++) {
sObject record = records[i];
if (record.getSObjectType() == Contact.sObjectType) {
contacts.add((Contact) record);
} else if (record.getSObjectType() == Lead.sObjectType){
leads.add((Lead) record);
} else if (record.getSObjectType() == Account.sObjectType) {
accounts.add((Account) record);
}
}
}
}
}

 

 

2)public with sharing class CustomPaginationExt {
public List<Account> accounts{get;set;}
public Integer pageSize{get;set;}
public Integer noOfPages{get;set;}
public Integer pageNumber{get;set;}
private String baseQuery = 'select name, industry, annualRevenue from Account order by name';
private Integer totalNoOfRecs;

public CustomPaginationExt(ApexPages.StandardController controller) {
pageSize = 2;
totalNoOfRecs = [select count() from Account limit 50000];
getInitialAccountSet();
}

public PageReference getInitialAccountSet()
{
pageNumber = 0;
noOfPages = totalNoOfRecs/pageSize;

if (Math.mod(totalNoOfRecs, pageSize) > 0)
noOfPages++;

try{
accounts = Database.query(baseQuery + ' limit '+pageSize);
}
catch(Exception e){
ApexPages.addMessages(e);
}
return null;
}

public PageReference next(){
pageNumber++;

queryAccounts();
return null;
}
public PageReference previous(){
pageNumber--;
if (pageNumber < 0)
return null;

queryAccounts();
return null;
}

private void queryAccounts()
{
Integer offset = pageNumber * pageSize;
String query = baseQuery + ' limit '+pageSize +' offset '+ offset;
System.debug('Query is'+query);
try{
accounts = Database.query(query);
}
catch(Exception e){
ApexPages.addMessages(e);
}
}
}

hi i need help

Below is my code:

VF page:

<apex:page sidebar="false" showHeader="false" controller="communityCon1234" cache="true" contentType="text/csv#Error.csv" language="en-US">


<apex:repeat value="{!HeaderXLS}" var="a">

<apex:outputText value="{!a}">
</apex:outputText>

</apex:repeat>
<br/>
<apex:repeat value="{!fileLine}" var="b">
<apex:outputText value="{!b}"></apex:outputText>

</apex:repeat>
<br/>
</apex:page>

 

Controller:

 

 public List<String> getHeaderXLS()
    {
      List<String> listString1 = new List<String>();
     listString1.add('phnnumber');
      listString1.add('name');
   
      return  listString1;
    }
    public List<String> getFileLine()
    { List<String> listString = new List<String>();
     listString.add('123456');
      listString.add('urvashi');
      return listString;
      
    }

 MY problem here is i wana display the values of listString and listString1 in different columns in excel file.

like

phnnumber    name

123456           urvashi

 

The the size of listString is not fixed.It varies depending upon the code.

How do i do this?
Please help.

And how do i insert<br/> tag in btwn vf page so that it doesnot come in the excel file.

hello,

Can anyone help

I m new to Salesforce please help.

I have a picklist with some values of fruits in it.

Example:

Apple Grapes Banana etc.

I have sorted these values alphabetically.

But now i want a default value to be added in picklist like example: '--Select value--'

Can i pass this value directly to the constructor to make it default to picklist?

Or should I add it first to the select list.

 

Please help

Thanks.

 

Hi,i build a multiple selectlist i want to show some items to be selected when the page renders initially  how to accomplish that any guidance ??

Hi,

 

I am new to Salesforce. Please help me in implementing following

 

In my Apex code, i have name of selected object in a Variable
I need a piece of code which returns name of the fields which are external ids in that selected object.

 

 

  • June 28, 2013
  • Like
  • 0

Accounts is a custom object.i have to retrieve the  account type on the basis of Name.
I am able to retrieve the id and i'm  getting  account type in debug. But, it isnt displayed in the VF page.
Please have a look at the code..

 

Given below is the code of Class and VF page

<apex:page controller="SearchByName">
 <apex:form >
  <apex:outputLabel style="font-weight:bold;" value="Search By Name" ></apex:outputLabel>
        <apex:inputText value="{!textData}"/> 
<apex:commandButton action="{!search}" value="Search" id="search" rerender="out, msgs" status="status"/>
 </apex:form>
 <!------Doesnt print the first name and account type------->
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Accounts}" var="c" >
  <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:outputField value="{!c.First_Name__c}" />
  </apex:column>
  <apex:column >
                <apex:facet name="header">Account Type</apex:facet>
                <apex:outputField value="{!c.Account_Type__c}" />
  </apex:column>

     
  </apex:pageBlockTable>
  </apex:pageBlock>
  
     <!------------- Getting the value of var "c"------------>
   <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="searching...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    
                    <apex:dataList value="{!Accounts}" var="c">a:{!c}</apex:dataList>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
 </apex:page>

 

public class SearchByName
{
 List<Account__c> Accounts;
private String textdata = null;

    public String getTextData() { return textdata; }
    
    public void setTextData(String data) { textdata = data; }
    
        
        
        public void search(){            
           
            Accounts = Database.query('SELECT First_Name__c,Account_Type__c  FROM Account__c where First_Name__c = :textdata');
            system.debug('Accounts>>>>'+Accounts);
       }    
        public List<Account__c> getAccounts() {
                
                return Accounts;
        }
        
       
}

 

  • June 28, 2013
  • Like
  • 0

I'm tring to optimize the code below.

I'm looking for a structure where i can put the picklist's values and after (with just a condition) i want check the condition for all the values in the structure.

if ((lead.Status.trim()=='Archived' || lead.Status.trim()=='False'||lead.Status.trim()=='Lead - Never'))

 

should be like this:

structure=['Archived','False','Lead - Never']; 
if ((lead.Status.trim()==structure))

 

I can not find anything, do you know how i can do this?

Thanks in advantage for any advice.

Br

  • June 28, 2013
  • Like
  • 0

HI All,

 

I m trying to dispaly a multipicklist as checkboxes in vf page but not succeeding.

 

How can I display the picklists in below showed style.

 

Name of the field : testpick__c

values : a, b, c, d, e

Object name: test__c

 

Expected Output:

                                A                     B                        C                       D                      E

 

Testpick                   X                      X                        X                      X                        X 

 

 

Thanks in advance..........