• SpaceManSpiff
  • NEWBIE
  • 0 Points
  • Member since 2012

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

I have written a trigger on the Campaign Member object that gives users access to our subscription service when their campagn status changes to 'Free Trial'. The trigger works without fail but the test is failing because of this error: 

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

 

Here is my code:

@isTest
public with sharing class Test_Trial_Campaign {
	
	static testMethod void test(){
		
		list<Id> IdLst = new list<Id>();
		list<CampaignMember> cMemL = new list<CampaignMember>();
		
		Campaign testC = new Campaign(isActive = true, ActualCost = 0, Name = 'SystemTest');
		insert testC;
		system.debug(testC);
		
		CampaignMemberStatus status = new CampaignMemberStatus(CampaignId = testC.Id, HasResponded = true, label = 'Free Trial', SortOrder = 2);
		
		insert new list<CampaignMemberStatus>{status};
			
		for (Integer i=0; i<10; i++){
			Lead testL = new Lead(FirstName = 'Test', LastName = 'Testerino'+i, email = 'test@testing.co'+i, Trial_Product__c = 'SUB-RTE-01');
			insert testL;
			
			CampaignMember mem = new CampaignMember(CampaignId = testC.Id, LeadId = testL.Id, Status = 'Free Trial');
			IdLst.add(testL.Id);
			
			insert mem;
			
			CampaignMember testerino = [SELECT Id, Status from CampaignMember where id =:mem.Id];
			
			system.debug(testerino);

		}
	
		list<Lead> lList = [SELECT Id, isConverted From Lead Where Id IN: IdLst];
		
		for (Lead l: lList){
			system.debug(l);
			system.assert(l.IsConverted == true);
		}
	}
}

 

It fails when attempting to insert the CampaignMemberStatus. I have tried multiple workarounds, all of which have failed. Any insight is greatly apprechiated. 

I get the following error when trying to access a controller Method from a VisualForce page: Visualforce Remoting Exception: only whitespace content allowed before start tag and not C (position: START_DOCUMENT seen C... @1:1)

 

Here is the Controller Class:

    @RemoteAction
    global static String saveUser(Credentials__c cred, Contact con) {
    	
    	cred.Lead_Number__c = integer.valueof(cred.Lead_Number__c);
        
        Http h = new Http();
        
/*
Initialize endpoint URL here
Code not included but works
*/
        
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        DOM.XMLNode root = doc.getRootElement();
        //Parses returned XML to String
        String result = Global_Methods.walkThrough(root);
        return (result.length()>0 ? result:'Error');
    }


 

And here is my call from the VisualForce Page:


		Global_Methods.saveUser(rec,con, function(result, event){
			var res = result.split(",",2);
			res[0] = parseInt(res[0]);
			if(res[0]!=1){
			alert(res[1]);
			    deleteId(record.Id);
			    return false;
			}
			else {
				RegisterTrial(con,rec,subProducts,type);
			}
		}, {escape:true});

 

The odd thing is that this works fine from a different VF page. I have no idea what this error means or how to fix it. Any insight is very much apprechiated. Thanks!


Hello all,

 

I am trying to create a few RemoteAction methods that can be accessed in multiple visualforce pages and Apex triggers to comunicate with a third party system in our company. I want to centralize these methods so all instances can be updated simultaneously.

 

The problem I am running into is that some of the Visualforce pages that I need this class to extend use the Opportunity StandardController and others use the Contact StandardController. Is there anyway that I can have a single Apex class extend across VF pages using the Opportunity and the Contact Standard controllers?

 

Thanks in advance.

 

-Clark

I have written a trigger on the Campaign Member object that gives users access to our subscription service when their campagn status changes to 'Free Trial'. The trigger works without fail but the test is failing because of this error: 

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

 

Here is my code:

@isTest
public with sharing class Test_Trial_Campaign {
	
	static testMethod void test(){
		
		list<Id> IdLst = new list<Id>();
		list<CampaignMember> cMemL = new list<CampaignMember>();
		
		Campaign testC = new Campaign(isActive = true, ActualCost = 0, Name = 'SystemTest');
		insert testC;
		system.debug(testC);
		
		CampaignMemberStatus status = new CampaignMemberStatus(CampaignId = testC.Id, HasResponded = true, label = 'Free Trial', SortOrder = 2);
		
		insert new list<CampaignMemberStatus>{status};
			
		for (Integer i=0; i<10; i++){
			Lead testL = new Lead(FirstName = 'Test', LastName = 'Testerino'+i, email = 'test@testing.co'+i, Trial_Product__c = 'SUB-RTE-01');
			insert testL;
			
			CampaignMember mem = new CampaignMember(CampaignId = testC.Id, LeadId = testL.Id, Status = 'Free Trial');
			IdLst.add(testL.Id);
			
			insert mem;
			
			CampaignMember testerino = [SELECT Id, Status from CampaignMember where id =:mem.Id];
			
			system.debug(testerino);

		}
	
		list<Lead> lList = [SELECT Id, isConverted From Lead Where Id IN: IdLst];
		
		for (Lead l: lList){
			system.debug(l);
			system.assert(l.IsConverted == true);
		}
	}
}

 

It fails when attempting to insert the CampaignMemberStatus. I have tried multiple workarounds, all of which have failed. Any insight is greatly apprechiated. 

I get the following error when trying to access a controller Method from a VisualForce page: Visualforce Remoting Exception: only whitespace content allowed before start tag and not C (position: START_DOCUMENT seen C... @1:1)

 

Here is the Controller Class:

    @RemoteAction
    global static String saveUser(Credentials__c cred, Contact con) {
    	
    	cred.Lead_Number__c = integer.valueof(cred.Lead_Number__c);
        
        Http h = new Http();
        
/*
Initialize endpoint URL here
Code not included but works
*/
        
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        DOM.XMLNode root = doc.getRootElement();
        //Parses returned XML to String
        String result = Global_Methods.walkThrough(root);
        return (result.length()>0 ? result:'Error');
    }


 

And here is my call from the VisualForce Page:


		Global_Methods.saveUser(rec,con, function(result, event){
			var res = result.split(",",2);
			res[0] = parseInt(res[0]);
			if(res[0]!=1){
			alert(res[1]);
			    deleteId(record.Id);
			    return false;
			}
			else {
				RegisterTrial(con,rec,subProducts,type);
			}
		}, {escape:true});

 

The odd thing is that this works fine from a different VF page. I have no idea what this error means or how to fix it. Any insight is very much apprechiated. Thanks!


Hello all,

 

I am trying to create a few RemoteAction methods that can be accessed in multiple visualforce pages and Apex triggers to comunicate with a third party system in our company. I want to centralize these methods so all instances can be updated simultaneously.

 

The problem I am running into is that some of the Visualforce pages that I need this class to extend use the Opportunity StandardController and others use the Contact StandardController. Is there anyway that I can have a single Apex class extend across VF pages using the Opportunity and the Contact Standard controllers?

 

Thanks in advance.

 

-Clark