• Newbie__Salesforce
  • NEWBIE
  • 174 Points
  • Member since 2017

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 5
    Questions
  • 23
    Replies
I need the id of selected values from selectlist in my apex

page:
<apex:page controller="test">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockSection>
                    <apex:OutputPanel >
                        <apex:selectList value="{!selectedwing}" size="5" multiselect="true" >
                            <apex:selectOptions value="{!ListOfwing}"/>
                        </apex:selectList>
                    </apex:OutputPanel>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form> 
    </apex:page>
controller:
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.name , u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}

 
suppose consider account and contact objects.  in creation of contact their shows account lookup field ,press the lookup icon shows the all accounts list in new window.my question is it is possible to edit that list. Like that list shows who doesn't have contacts or who have less than some vale of recors(take 10),these names only display that list.By using this list only select one account and create a contact. 
please help me this.

thanks in advance
else if(ApexPages.currentPage().getParameters().get('RecordType') =='0127F000000erM4'){
             PageReference pageRef1 = new PageReference('/apex/Case_CustomEditPage');
             pageRef1.setRedirect(true);
             return pageRef1;
             }

 
I have 100% coverage, but I still haven't scenarios for check. How to write good and bad scenarios for test class?
This is my helper:
public with sharing class JobHelper {

public static List<Task> taskList = new List<Task>();

public static void afterInsert(List<Job__c> newList) {

    for(Job__c job : newList){ 
        if(job.Stage__c == 'Closed'){
            createTask(job.OwnerId, 'Closed');
        }
        if(job.Stage__c == 'Open'){
            createTask(job.OwnerId, 'Open');
        }
    }
    insertTask(newList);
}

public static void afterUpdate(List<Job__c> newList, Map<ID, Job__c> oldMap) {

    for(Job__c job : newList){ 
        if(job.Stage__c == 'Closed' && oldMap.get(job.Id).Stage__c != 'Closed'){
            createTask(job.OwnerId, 'Closed');
        }
        if(job.Stage__c == 'Open' && oldMap.get(job.Id).Stage__c != 'Open'){
            createTask(job.OwnerId, 'Open');
        }
    }
    insert taskList;
}

public static List<Task> createTask(Id ownId, String subj){
    taskList.add(new Task(OwnerId = ownId, Subject = subj));
    return taskList;
}
}
Trigger:
trigger JobTrigger on Job__c (after insert, after update) {

if(Trigger.isAfter && Trigger.isInsert) {
    JobHelper.afterInsert(Trigger.new);
}
else if (Trigger.isAfter && Trigger.isUpdate) {
    JobHelper.afterUpdate(Trigger.new, Trigger.oldMap);
}
}
My test-try:
@isTest
private class JobTest {


public static List<Job__c> jobList = new List<Jobn__c>();

static testMethod void createTaskTest(){

    Job__c job1 = new Job__c(
        Stage__c = 'Closed',
    );
    jobList.add(job1);

    Job__c job2 = new Job__c(
        Stage__c = 'Open',
    );
    jobList.add(job2);

    insert jobList;

    List<Task> taskListTest = new List<Task>();
    Task task1 = new Task(Subject = 'Closed');
    taskListTest.add(task1);

    Task task2 = new Task(Subject = 'Open');
    taskListTest.add(task2);

    insert taskListTest;

    JobHelper j = new JobHelper();
    //System.assert(taskListTest == j.taskList);
}
}

 

Hi,

I need to create a custom button on Opportunity Layout then when this button is pressed I need to create a new Quote and redirect to a VF page that I will create afterward. Someone can help me with this, please? I wrote some code but I don't know if it's good or bad.

Just need to create a new Quote on the current Opportunity which I'm in.

 

public class MyController {

    public String currentRecordId {get;set;}
    public String parameterValue {get;set;}
    public Opportunity opp {get;set;}
    
    public MyController(ApexPages.StandardController controller){
        currentRecordId = ApexPages.currentPage().getparameters().get('id');
        opp = [Select id From Opportunity where id =: currentRecordId];
		parameterValue = ApexPages.currentPage().getparameters().get('nameParam');
        
        Quote qo = new Quote();
        insert qo;
    }
    
}
Your queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types  then while executing in asyn process the value of the variables are changed will it work on old value or new value??

Thanks in advance!
 
I have tried to delete duplicate records based on static field names but I want to delete records based on configurable fields.

My code is
global class RemovalofDuplicateLeads implements 
    Database.Batchable<sObject>, Database.Stateful {

    global Map<String,Lead> mapString_Lead = new Map<String,Lead>();  

    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT Name, Email from Lead where LastModifiedDate = Today'
        );
    }

    global void execute(Database.BatchableContext bc, List<Lead> scope) {

        List<Lead> lstduplicate = new List<Lead>();
        
        for(Lead lead : scope) {
            if(! mapString_Lead.containsKey(lead.Email)) {
                mapString_Lead.put(lead.Email , lead);
            } else {
                lstduplicate.add(lead);
            }
        }
        
        System.debug(lstduplicate);
        if(lstduplicate.size() > 0) {
            delete lstduplicate;
        }
    }
    
    global void finish(Database.BatchableContext bc) {        
   
    }
}
for(Case caseObj : [SELECT Id,
								   ContactId,
								   AccountId
						    FROM   Case]) {
			if(String.isNotBlank(caseObj.AccountId)){
		    	if(!mapId_Map.containsKey(caseObj.AccountId)) {
					mapId_Map.put(caseObj.AccountId,new Map<Id,List<Case>>());
					mapId_Map.get(caseObj.AccountId).put(caseObj.ContactId,new List<Case>());
					System.debug('Inside If');
		    	}
		    	mapId_Map.get(caseObj.AccountId).get(caseObj.ContactId).add(caseObj);
			}
		}
	System.debug('Map of Map------>>'+mapId_Map);

Getting null pointer exception while adding cases
My query is
List<Order> lstOrder = [SELECT Id,(SELECT Id FROM Attachments),(SELECT Id,PricebookEntry.Product2.Name FROM OrderItems) FROM Order WHERE Id IN :lstId];

I have tried to display using repeat
<apex:pageBlock >
				<apex:repeat value="{!lstOrder}" var="myFeedVar" >
					<tr>
						<td>
							<apex:repeat value="{!myFeedVar.Attachments}" var="item" >
					       		<apex:image value="/servlet/servlet.FileDownload?file={!item}" id="someImage" height="500px" width="500px"/>  
					    	</apex:repeat>
					   	</td>
					   	<td>
					   		<apex:repeat value="{!myFeedVar.OrderItems}" var="item" >
					       		<apex:outputField value="{!item.Product2.Name}">
					    	</apex:repeat>
					   	</td>
				       	<td>
				       		<apex:commandButton value="LIKE"/>
				       	</td>
				   </tr>
				    
				    <br/><br/>
				</apex:repeat>	
	       	</apex:pageBlock>

I am unable to display OrderItems in repeat. 
I have to retrieve tags from HTML body by iterating my body is a search result page I want to fetch title, Description and links from it 
I need the id of selected values from selectlist in my apex

page:
<apex:page controller="test">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockSection>
                    <apex:OutputPanel >
                        <apex:selectList value="{!selectedwing}" size="5" multiselect="true" >
                            <apex:selectOptions value="{!ListOfwing}"/>
                        </apex:selectList>
                    </apex:OutputPanel>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form> 
    </apex:page>
controller:
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.name , u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}

 
Hi, 

  I have a class below which has no code I want to get coverage for below class
public class PP_HandleException extends Exception {
  
}
Wrote test class as mentioned blelow. Still showing 0% as code coverage 
@isTest(seealldata=false)
public class PP_HandleExceptionTest{
    static testMethod void PP_HandleException(){
        Test.startTest();
       PP_HandleException PP = new PP_HandleException('test');
    
        Test.stopTest();
    }  
}

  Please suggest me how to get code coverage.

Thanks
Sudhir
 
Hello Everyone,
Need a help with email services. I'm trying to create cases throgh emails by using InboundEmailHandler. Our customers have a predefined email format (please check the screenshot). Once the email is sent to our organization, a case has to be created but it shouldn't just dump the email body in the description field. Each of the value in the email belongs to a particular field of case object. I've researched online and found out that String.Split is the way to go. However, I'm having trouble to write the code (still an amateur at Apex). Can any one please help me how to split the lines of email body and assign them to fields in the case object. Please explain it through w.r.t to the email body provided. Thank you!

For ex:  Problem Description infromation should be popualted in case descriton field
             Warranty information should be populated in product_warranty__c custom field. 

P.S: We only get emails in text format. No html is involved.
User-added image
  • September 24, 2018
  • Like
  • 0
Hi, I have the following text:

    String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
I want to replace all the `<br>`with the new line `\n`.

So I used this function:

    target = target.replaceAll('<br>', '\n');  but I have this error: Error on line 38, column 1: System.StringException: No match found. And if I try to replace with another string for example:

    target = target.replaceAll('<br>', 'test');   It works like a charm...

Here it's the full code for this:
 
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
    
    target = target.replaceAll('<br>', '\n');
    
    String regExp = '(.*)';
    Pattern myPattern = Pattern.compile(regExp);
    Matcher myMatcher = myPattern.matcher(target);
    
    System.debug('Matches: ' + myMatcher.matches());
    System.debug('Group 0: ' + myMatcher.group(1));

 
suppose consider account and contact objects.  in creation of contact their shows account lookup field ,press the lookup icon shows the all accounts list in new window.my question is it is possible to edit that list. Like that list shows who doesn't have contacts or who have less than some vale of recors(take 10),these names only display that list.By using this list only select one account and create a contact. 
please help me this.

thanks in advance
else if(ApexPages.currentPage().getParameters().get('RecordType') =='0127F000000erM4'){
             PageReference pageRef1 = new PageReference('/apex/Case_CustomEditPage');
             pageRef1.setRedirect(true);
             return pageRef1;
             }

 
Hello guys

I am having one scenario, while creating contact, I will be checking the email id of contact and if duplicate email id found for specific record then I have a Checkbox__c field on account and it should be unchecked.
by default Vheckbox__c will be checked.
While creating contact for a particular account,if email is already found on that particular account then checkbox should be unchecked
I have 100% coverage, but I still haven't scenarios for check. How to write good and bad scenarios for test class?
This is my helper:
public with sharing class JobHelper {

public static List<Task> taskList = new List<Task>();

public static void afterInsert(List<Job__c> newList) {

    for(Job__c job : newList){ 
        if(job.Stage__c == 'Closed'){
            createTask(job.OwnerId, 'Closed');
        }
        if(job.Stage__c == 'Open'){
            createTask(job.OwnerId, 'Open');
        }
    }
    insertTask(newList);
}

public static void afterUpdate(List<Job__c> newList, Map<ID, Job__c> oldMap) {

    for(Job__c job : newList){ 
        if(job.Stage__c == 'Closed' && oldMap.get(job.Id).Stage__c != 'Closed'){
            createTask(job.OwnerId, 'Closed');
        }
        if(job.Stage__c == 'Open' && oldMap.get(job.Id).Stage__c != 'Open'){
            createTask(job.OwnerId, 'Open');
        }
    }
    insert taskList;
}

public static List<Task> createTask(Id ownId, String subj){
    taskList.add(new Task(OwnerId = ownId, Subject = subj));
    return taskList;
}
}
Trigger:
trigger JobTrigger on Job__c (after insert, after update) {

if(Trigger.isAfter && Trigger.isInsert) {
    JobHelper.afterInsert(Trigger.new);
}
else if (Trigger.isAfter && Trigger.isUpdate) {
    JobHelper.afterUpdate(Trigger.new, Trigger.oldMap);
}
}
My test-try:
@isTest
private class JobTest {


public static List<Job__c> jobList = new List<Jobn__c>();

static testMethod void createTaskTest(){

    Job__c job1 = new Job__c(
        Stage__c = 'Closed',
    );
    jobList.add(job1);

    Job__c job2 = new Job__c(
        Stage__c = 'Open',
    );
    jobList.add(job2);

    insert jobList;

    List<Task> taskListTest = new List<Task>();
    Task task1 = new Task(Subject = 'Closed');
    taskListTest.add(task1);

    Task task2 = new Task(Subject = 'Open');
    taskListTest.add(task2);

    insert taskListTest;

    JobHelper j = new JobHelper();
    //System.assert(taskListTest == j.taskList);
}
}

 
Hi newbee hear! keep getting error at the end of challenge saying 'the field isn't in the object or is of wrong data type' Double checked, deleted and re done still the error! Please help Steve
Hi, I have created a detail custom button of url type and passing Opportunity Date as shown below.

/apex/vfpage?oliId={!OpportunityLineItem.Id} && oppDate={!Opportunity.customDate__c}

And in apex constructor i am receiving the custom date value as below.

customDate = Date.valueOf(ApexPages.currentPage().getParameters().get('oppDate'));
But I am receiving error as
"Argument cannot be null. An unexpected error has occurred. Your development organization has been notified. "

How to pass the oppDate from url to constructor.
 
Hi All,

Our team has a requirement regarding integrating an on-premise system with Salesforce. The user in Salesforce should be able to upload attachment/file on a record without storing it in Salesforce - then the attachment/file will be uploaded in the on-premise system with the details regarding the related record.

Is this possible? If possible, what are the steps that we need to do? Thanks!

Hi,

I need to create a custom button on Opportunity Layout then when this button is pressed I need to create a new Quote and redirect to a VF page that I will create afterward. Someone can help me with this, please? I wrote some code but I don't know if it's good or bad.

Just need to create a new Quote on the current Opportunity which I'm in.

 

public class MyController {

    public String currentRecordId {get;set;}
    public String parameterValue {get;set;}
    public Opportunity opp {get;set;}
    
    public MyController(ApexPages.StandardController controller){
        currentRecordId = ApexPages.currentPage().getparameters().get('id');
        opp = [Select id From Opportunity where id =: currentRecordId];
		parameterValue = ApexPages.currentPage().getparameters().get('nameParam');
        
        Quote qo = new Quote();
        insert qo;
    }
    
}
Hello everyone, 

I have commandButton in my visualforce page that retrieves the id in a search box, searches for an object, and modifies the object founded.

I need to display an error message if the id does not exist or the object is already updated?
Any Help please.